PRACTICE EXAM 1 - SAMPLE ANSWERS 1. (a) C, D, B, E, A (b) E, D (c) 12, 17, 25 (d) 8 (e) 38 - <<< CORRECTION!!! (f) The rise of email has led to a huge decrease in postal mail. (g) C, 7, N 2. (a) 15, 9, 9, 18, 0 (b) def cone_volume(height, radius) return Math::PI * radius * radius * height / 3 end (c) print cone_volume(10,4) + cone_volume(5,6) + cone_volume(7,2) (d) j 1 4 9 16 25 k 3 5 7 9 11 (e) The square of n (f) Since mystery doesn't return anything, you can't add the results of three of these function calls. 3. (a) "apple" 7 "peach" false cherry banana orange ["peach", "grape", "orange", "melon"] (b) numlist primes [3,5,7,9] [2] [5,7] [2,3] 4. (a) list[0] 1..list.length-1 list[i] min_so_far = list[i] min_so_far (b) list.first, list.length == 1 list[1..list.length-1] list.first < min_without_first_element (c) The function calls itself. 5. (a) list.length-1 i >= 0 nil (b) O(n) (c) FALSE (d) [3, 8, 7, 4, 5] [3, 4, 7, 8, 5] [3, 4, 5, 8, 7] [3, 4, 5, 7, 8] (e) c (both are O(n**2) in the worst case)