


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



1. The adjacent figure illustrates that the fifth triangle number is: (See page 588 in E3 or p558 in E4.) a. 3 b. 4 c. 6 d. 10 e. 15 [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] 2. The recursive method for calculating the n th^ triangle number T ( n ) is based on the stopping condition that T (1) = 1 and the reduction identity: a. T ( n ) = n + T ( n − 1 ) b. T ( n ) = T ( n + 1 ) + n c. T ( n ) = T ( n − 1 ) − n d. T ( n ) = T ( n − 1 ) + 1 3. We can find a formula for the n th^ triangle number T ( n ) which does not involve recursion. The correct formula is: a. T ( n ) = n ( n − 1 ) 2 b. T ( n ) = n ( n + 1 ) 2 c. T ( n ) = 3 n^2 2 d. T ( n ) = 3 n + 1 2 4. The following recursive method getArea for calculating triangle numbers T ( n ) has a little problem when the user tries to find T (0). That problem is called: a. infinite recursion b. linear regression c. septic shock d. asymptotically unstable public int getArea() { if (width == 1) return 1; Triangle smallerTriangle = new Triangle(width – 1); int smallerArea = smallerTriangle.getArea(); return smallerArea + width; } 5. We can fix the problem in the above method getArea by replacing the if statement with: a. if (width <= 1) return 1; b. if (width <= 1) return 0; c. if (width <= 0) return 1; d. if (width <= 0) return 0; 6. The n th^ square number S ( n ) is given by the formula S ( n ) = n^2. The figure illustrates the recursive identity: a. S ( n ) = S ( n − 1 ) + 2 n − 1 b. S ( n ) = S ( n − 1 ) + S ( n − 2 ) c. S ( n ) = S ( n − 1 ) + n 7. Sometimes, a recursive identity for one quantity can solve the problem for another quantity. Inspecting the adjacent figure, express the n th^ square number S ( n ) in terms of triangle numbers. a. S ( n ) = T ( n ) + T ( n − 1 ) b. S ( n ) = n + T ( n − 1 ) c. S ( n ) = T ( n ) + T ( n + 1 ) 8. The adjacent figure illustrates the hexagonal numbers H ( 1 ) = 1 , H ( 2 ) = 7 and H ( 3 ) = 19. By adding a layer to this beautiful ice-crystal you can verify that H ( 4 ) = 37. Noting that the difference of any two hexagonal numbers is a multiple of 6, find a recursion to compute the hexagonal numbers.
Grade = 36
9. Find an explicit formula for the hexagonal numbers H ( n ). Notice the adjacent figure contains 3 copies of the square number S (4). The remaining terms correct for over counting. a. H ( n ) = 3 n^2 − 3 n + 1 b. H ( n ) = 2 n^2 + 3 n + 1 c. H ( n ) = 3 n^2 − 2 n 10. Sliced-Up Pizza: Now the slices cut the crystal into 6 triangles. Compute the hexagonal numbers H ( n ) in terms of triangle numbers T ( n ). Because of over counting, it is not true that H ( n ) = 6 ⋅ T ( n ). a. H ( n ) = 3 ⋅ T ( n ) + 3 ⋅ T ( n − 2 ) − 2 b. H ( n ) = 6 ⋅ T ( n ) − 6 n + 1 c. Both of these B: Permutations, Palindromes 1. The string "no" has how many permutations including itself? (See page 592 in E3 or p573 in E4.) a. 1 b. 2 c. 6 d. 24 e. 120 2. The string "tiger" has how many permutations including itself? (See page 592 in E3 or p573 in E4.) a. 1 b. 2 c. 6 d. 24 e. 120 3. In the string “ JAVA ”, the letter ‘A’ is repeated. Thus, the number of distinct permutations is not 24 since for example these permutations are the same: JAVA = JAVA Taking this repetition into account, the number of distinct permutations of “ JAVA ” is: a. 3 b. 4 c. 6 d. 12 e. 24 4. The three shorter strings of length 2 used in finding the permutations of "cat" recursively include all of the following except: (See page 594 in Ed3 or p 573 in Ed4.) a. "at" b. "ct" c. "ca" d. "tc" 5. We wish to find the permutations of the 6 - letter word “DRAGON”. Our recursive algorithm will call itself on how many words of length 5? a. 1 b. 5 c. 6 d. 7 6. The number of permutations of the 6-letter word “DRAGON” is: _ _ _ a. 4! b. 5! c. 6! d. 7! 7. We wish to find the permutations of the string myWord. Which of these statements will find the shorter word obtained by deleting the i th^ letter (that is, its index = i ) from the original string myWord? a. String shorterWord = myWord.substring(0, i) + myWord.substring(i+1); b. String shorterWord = myWord.substring(0, i+1) + myWord.substring(i+1); c. String shorterWord = myWord.substring(0, i-1) + myWord.substring(i+1); d. String shorterWord = myWord.substring(0, i) + myWord.substring(i);
7. Alan Turing showed that it is possible to write a halt checker program that can check whether every program halts on a particular input. a. true b. false (See page 6 10 in Ed3 or p57 8 6 in Ed4.) 8. When a set of cooperating methods call each other repeatedly, it is called … recursion. (See page 611 or p579 in Ed4.) a. iterative b. mutual c. infinite d. illegal Create Three of Your Own Multiple Choice Questions for This Chapter: Include answer options and circle the correct answer. A good topic choice would be Mutual Recursions or the Expression Calculator program since no good questions were provided for you. Q1. Q2. Q3.