1. Prove that 11! 2 2! n n ! (n 1)! 1 whenever n is a positive integer. We use mathematical induction. In the basis step, for n = 1, the equation states that 1.1! = (1+1)!-1, and this is true because both sides of the equation evaluate to 1. For the inductive step, we assume that 1 .1! + 2 . 2! + _ _ _ + k .k! = (k + 1)! - 1 for some positive integer k. We add (k + 1).(k + 1)! to the left hand side to find that 1 .1! + 2 .2! + _ _ _ + (k + 1) .(k + 1)! = (k + 1)! - 1 + (k + 1)(k + 1)! The right hand side equals (k + 1)!(k + 2) -1 = (k + 2)! -1. This establishes the desired equation also for k +1, and we are done by the principle of mathematical induction. 2. Give a recursive definition of the sequence {an }, n 1, 2,3, a) an 4n 2 n b) an 1 (1) c) an n(n 1) 2 d) an n 3. Give a recursive algorithm for finding the maximum of a finite set of integers, making use of the fact that the maximum of n integers is the larger of the last integer in the list and the maximum of the first n 1 integers in the list. The recursion is something like this: max( a[1...n] ) = the larger of max( a[1...(n-1)] ) and a[n] So you'd write something like: max( int a[], int maxIdxToConsider ) { if (maxIdxToConsider == 0) return a[0]; int prevMax = max( a, maxIdxToConsider - 1 ); if ( prevMax > a[maxIdxToConsider] ) return prevMax; else return a[maxIdxToConsider]; } 4. A particular brand of shirt comes in 12 colors, has a male version and a female version, and comes in three sizes for each sex. How many different types of this shirt are made? Ans) 12.2.3= 72 different types of shirt. 5. How many positive integers less than 1000 a) are divisible by 7? b) are divisible by 7 but not by 11? c) are divisible by both 7 and 11? d) are divisible by either 7 or 11? e) are divisible by exactly one of 7 and 11? f) are divisible by neither 7 nor 11? g) have distinct digits? h) have distinct digits and are even? Solution. (a) Every 7th number is divisible by 7. Since 1000 = (7)(142) + 6, there are 142 multiples of seven less than 1000. (b) Every 77th number is divisible by 77. Since 1000 = (77)(12) + 76, there are 12 multiples of 77 less than 1000. We don’t want to count these, so there are 142 − 12 = 130 multiples of 7 but not 11 less than 1000. (c) We just figured this out to get (b)—there are 12. (d) Since 1000 = (11)(90) + 10, there are 90 multiples of 11 less than 1000. Now, if we add the 142 multiples of 7 to this, we get 232, but in doing this we’ve counted each multiple of 77 twice. We can correct for this by subtracting off the 12 items that we’ve counted twice. Thus, there are 232-12=220 positive integers less than 1000 divisible by 7 or 11. (e) If we want to exclude the multiples of 77 altogether, we need only subtract them off a second time; there are thus 220-12=208 multiples of 7 or 11 but not both. (f) There are 999 positive integers less than 1000. We’ve accounted for 220 as multiples of 7 or 11, so there are 779 that are divisible by neither. (g) There are 9 one-digit positive numbers. For two-digit numbers, the first digit may be anything from 1 to 9, while the second may be anything from 0 to 9 except the first digit. We thus have 9 choices for each digit, and so have 81 two-digit numbers with distinct digits. For three-digit numbers, we have 9 choices for the first digit, 9 for the second, and 8 for the third, for a total of 648 three-digit numbers with distinct digits. Thus, there are 9+81+648=738 numbers less than 1000 with distinct digits. (h) This time things get a little tricky. There are 4 one-digit even numbers. For two digit numbers, there are 4 nonzero choices for the second digit, upon which we have 8 choices of first digit, or the last digit could be zero, upon with we have 9. There are thus 41 even two-digit numbers with distinct digits. For three-digit numbers, there are 4 nonzero last digits, upon which there are 8 choices of first digit and 8 of middle digit (for (4)(8)(8)=256 choices, or the last digit is zero, upon which there are 9*8=72 such numbers. There are thus 4+41+256+72=373 even numbers less than 1000 with distinct digits. 6. There are six different candidates for governor of a state. In how many orders can the names of the candidates be printed on a ballot? Ans) 720 ( 6 x 5 x 4 x 3 x 2 x 1) The first name can go in any one of the six positions on the ballot. The second name in one of the remaining 5 The third name in one of the remaining 4 The fourth name in one of the remaining 3 The fifth name in one of the remaining 2 The sixth name in the only place remaining 7. Describe a graph model that represents a subway system in a large city. Should edges be directed or undirected? Should multiple edges be allowed? Should loops be allowed? Solution. The vertices should represent subway stops, and the edges should represent subway lines that go from one station to the next. The edges should be directed, since each rail usual has trains going only one direction. Multiple edges should be allowed for when there are rails going both directions between two stations; also some routes are express, so this may facilitate the need for more than one edge in the same direction. Loops should not be allowed, since we don't need to go from a station to itself. (Thus we want a directed multigraph, but not a pseudograph.) 8. Represent this graph with an adjacency matrix. a b c d e a 0 1 0 1 0 b 1 0 1 1 1 c 0 1 1 0 0 d 1 0 0 0 1 e 0 0 1 0 1 9. Does each of these lists of vertices form a path in the following graph? Which paths are simple? Which are circuits? What are the lengths of those that are paths? a) a, b, e, c, b b) a, d , a, d , a c) a, d , b, e, a d) a, b, e, c, b, d , a Paths & lengths-> a) 4, b) 4 Simple Paths-> none Circuits-> none 10. What is the value of each of these postfix expressions? a) 5 2 1 - - 3 1 4 + + 32 b) 9 3 / 5 + 7 2 - 40 c) 3 2 2 5 3 - 8 4 / 32