#OK to post test #Kent Mei, 12/15/20, Final Exam #--------------------------------- #Part 1 #a) #Using an explicit formula, we get that the number of ways to walk from [0,0,0] to [30,25,20] where the allowed steps are [1,0,0] or [0,1,0], or [0,0,1] is equal to (30+25+20)!/(30!*25!*20!) #The answer is 2478456799816702091914145225486880 ways. #(To double check, we can use NuW([30,25,20],{[1,0,0],[0,1,0],[0,0,1]}); from the ComboProject3.txt and we get the same answer). #~~~~~~~~~~ #b) #We can use NuGW([30,25,20],{[1,0,0],[0,1,0],[0,0,1]}); from ComboProject3.txt. #The answer is 41512613892711511465063226481480 ways. #~~~~~~~~~~ #c) #NuGW([30,25,20],{[1,0,0],[0,1,0],[0,0,1],[1,1,1],[2,2,2]}); #The answer is 702157829467026190582908694797444 ways. #~~~~~~~~~~ #d) #We can modify NuGW to get the answer: NuGWAlt:=proc(Pt,A) local a: option remember: if (Pt[1]<0 or Pt[2]<0 or Pt[3]<0 or Pt[1] n or not member(k mod m, C) then return 0: fi: if k = n then return 1: fi: add(pnkDC(n-k,i,d,C,m),i=1..k-d): end: pnDC:=proc(n,d,C,m) local i: add(pnkDC(n,i,d,C,m), i = 1..n): end: #Alternatively, we can use the generating function to find the answer. pnOddDistinctSeq:=proc(N) local f,q,i: f:=mul(1+q^(2*i+1),i=0..trunc(N/2)): f:=taylor(f,q=0,N+1): [seq(coeff(f,q,i),i=1..N)]: end: #pnOddDistinctSeq(1000)[1000]; #So, we find that there are 517035762467311 integer partitions of 1000 with distinct and odd parts. #--------------------------------- #Part 6 #a) #The number of labeled trees with n nodes is n^(n-2). #Rooted trees choose 1 of the n nodes to be the root so in total, there are n^(n-1) rooted labelled trees #So, 31^30 = 550618520345910837374536871905139185678862401 #There are 550618520345910837374536871905139185678862401 rooted labelled trees with 31 vertices. #~~~~~~~~~~ #b) #Considering rooted labelled trees with 31 vertices where the root has exactly two children. #We choose 1 out of 31 vertices to be the root. #Since the root must have two children, the children are the roots of their own rooted labelled trees except with no restrictions on the number of children for those. #We have to allocate a number x out of 30 vertices to be for one tree and a number 30-x vertices for the other tree. #We also have to choose x out of 30 labels to assign to the vertices in one tree and the rest are left over for the other tree. #Note that 1|29 is the same as 29|1, so we take the number we get divided by 2. #So, the total number of rooted labelled trees is 31 * Sum(binomial(30,x) * x^(x-1) * (30-x)^(29-x), x = 1..29) / 2; #The total number of rooted labelled trees with 31 vertices where the root has exactly 2 children is 205662364170099390000000000000000000000000000. #~~~~~~~~~~ #c) #Using SeqRTChild(S,N) from hw22KentMei.txt SeqRTchild:=proc(S,N) local eq, s, L: eq := 1: for s in S do eq := eq + (z^s / s!): od: L := FunEqToSeq(eq, z, N): [seq(L[n]*n!, n = 1..N)]: end: #SeqRTchild({1,3,4},31)[31]; #388391178300656853181332829972846230000000 rooted labelled trees with 31 vertices match the description. #~~~~~~~~~~ #d) #Using SeqRTchildNone(S,N) from hw22KentMei.txt SeqRTchildNone:=proc(S,N) local eq, s, L: eq := exp(z): for s in S do eq := eq - (z^s / s!): od: L := FunEqToSeq(eq, z, N): [seq(L[n]*n!, n = 1..N)]: end: #SeqRTchildNone({1,3,4},31)[31]; #2863465748628395267057869436794752181 rooted labelled trees with 31 vertices match the description. #--------------------------------- #Part 7 #a) BT:=proc(n) local Ans, BT1, BT2, i, j, k: option remember: if n = 1 then return {[]}: fi: Ans := {}: for i from 1 to n-1 do BT1 := BT(i): BT2 := BT(n-i): Ans := Ans union {seq(seq([BT1[j], BT[k]], j = 1..nops(BT1)), k = 1..nops(BT2))}: od: end: #BT(4) (assuming the description was supposed to be the set of such creatures with n leaves) is as follows: #{ [[[], []], [[], []]], # [[[[], []], []], []], # [[[], [[], []]], []], # [[], [[[], []], []]], # [[], [[], [[], []]]] } #~~~~~~~~~~ #b) b:=proc(n) local Ans, i: option remember: if n = 0 then return 0: fi: if n = 1 then return 1: fi: Ans := 0: for i from 1 to n-1 do Ans := Ans + bt(i)*bt(n-i): od: end: #We can see from the above code that b(1) = 1 and b(n) = Sum(b(i)*b(n-i), i = 1..n-1) for all n >= 1. #We define B(x) = Sum(b(n)*x^n, n = 0..infinity). #Note that b(0) = 0 since there are no complete binary trees with 0 leaves. # B(x) = Sum(b(n)*x^n, n = 0..infinity) # => B(x) = Sum(b(n)*x^n, n = 1..infinity) # => B(x)^2 = (Sum(b(n)*x^n, n = 1..infinity))^2 # => B(x)^2 = Sum( Sum(b(i)*b(n-i),i = 1..n-1), n = 1..infinity ) # => B(x)^2. = Sum( b(n)*x^n, n = 2..infinity ) # => x + B(x)^2 = x + Sum( b(n)*x^n, n = 2..infinity ) # => x + B(x)^2 = b(1)*x^1 + Sum( b(n)*x^n, n = 2..infinity ) # => x + B(x)^2 = Sum( b(n)*x^n, n = 1..infinity ) # => x + B(x)^2 = B(x) # As such, we have shown that x + B(x)^2 = B(x) as desired.