Test #2 Answer Key 1. F, 1, 4, T, F, 14, F, A or C, F, T 2. (a), (b), (c) 3. Tree: root: 5 children of 5: 6a 6b children of 6a: 9 8 children of 6b _ 7 children of 9: 10 _ children of 8: 12 11 children of 10: _ 13 4. Pass 1: B: 6 0 8 2 5 3 9 1 Pass 2: A: 8 6 2 0 9 5 3 1 5. (a) 3 min, 6 max (b) many answers possible 6. Tree: root: 12 children of 12: 9 _ children of 9: 8 7a children of 8: 7b 4 children of 7a: 3 0 children of 7b: 2 1 7. Pass 1: 230, 591, 201, 051, 791, 682, 394, 144, 925, 126, 877, 129 Pass 2: 201, 925, 126, 129, 230, 144, 051, 877, 682, 591, 791, 394 8. 9. c 00 n 10 e 010 j 011 g 111 q 1101 f 11000 t 11001 10. dv pv A 7 F B 9 A C 0 _ D 3 C E 5 D F 6 E G 6 C 11. 29, 2, 8, (A,C), (G,I) or (E,I) 12. 0 1 2 3 4 5 6 7 8 9 x 21 12 18 5 4 9 13 - - Bonus 1: Can one develop a program/algorithm that takes as input a program P and input I and decides whether or not P halts when executed on I. (see page 338) Bonus 2: Heapsort If memory can hold N records ... 1. Fill memory from input file 2. Build heap, start new run (sorted sublist) 3. As one removes values from heap, write value to disk and read a new value from input file. 4. If new value less than or equal to last outputted value, proceed to (3). 5. If new value greater than last value output, mark new value as "out of play" and proceed to (3) using one less value. 6. When all values are "out of play", end current run. Proceed to (2). 7. This produces runs of length 2*N on average.