CSCI 2720 Data Structures Spring 2004 Final Examination The final examination will be held Thursday, May 6 12:00-3:00 PM in 222 Boyd. The test will be closed book, no notes, and no calculators or other electronic devices with memory or communication capabilities. Coverage in the Lewis and Denenberg text: Chs. 1-5 (except for Section 2.3); Section 6.4; Chs. 7 and 8; Sections 9.1 (through heaps) and 11.3. Relative weight of course material: The examination will be comprehensive, but the topics starting with AVL trees (Section 7.3 in the Lewis and Denenberg text) will be weighted more heavily (relative to time spent in class) than the earlier topics and will comprise about 55% of the examination. Advice on studying for the final examination: In addition to the text sections covered and your class notes, homework sets 1-5 and programming projects 1-5 should be thoroughly understood. Review Questions for the final examination (only covering new topics) were handed out in class on April 27, and are available from the instructor (hard copy only). Note that the final examination will be comprehensive (see above), so the review questions provided earlier for Test 1 and Test 2 are still useful for final examination review. Review session: The last class, April 29, will be mostly devoted to review. Remember that classes that day are on a MONDAY SCHEDULE, so 2720 will meet 1:25-2:15. Short answers for most of the final exam review questions: 1(a) T 1(b) F 1(c) F 1(d) T 1(e) F 2(a) T 2(b) T 2(c) T 2(d) F 2(e) F 2(f) F 2(g) F 2(h) T 3(a) F 3(b) F 3(c) F 3(d) T 3(e) F 3(f) F 3(g) F 3(h) T 4(a) F 4(b) T 4(c) F 4(d) T 4(e) F 5(a) T 5(b) T 5(c) T 5(d) T 5(e) T 5(f) F 5(g) T 5(h) F 6(a) T 6(b) T 6(c) F 6(d) F 7(a) F 7(b) T 7(c) T 7(d) T 7(e) F 7(f) T 8 Did this in class on the last day in detail, both bottom-up and top-down. The two trees obtained were significantly different. 9 Precompute a table of ilog values for the byte-sized integers, calling it, say, bilog[ ] (256 bytes, as the values can be of type unsigned char; the maximum value is 7 = ilog(128) = ilog(129) = ... = ilog(255)). Then the code could be: { unsigned char * ucptr = reinterpret_cast( &n ); if ( ucptr[0] ) return (24 + bilog[ ucptr[0] ]); else if ( ucptr[1] ) return (16 + bilog[ ucptr[1] ]); else if ( ucptr[2] ) return (8 + bilog[ ucptr[2] ]); else if ( ucptr[3] ) return bilog[ ucptr[3] ]; else return 0x7fffffff; } 10 Here are the internal nodes and the non-null pointers in them: level 0, the root, has ptr at index H to level 1 child and ptr at index Z to leaf (ZEBU); level 1, has ptr at index A to level 4 child and ptr at index E to level 5 child; level 4, has ptrs at indices #, E, and S to leaves (HART), (HARTEBEEST) and (HARTSHORN), respectively, where # is the index for end of word; level 5, has ptr at index A to leaf (HEART) and ptr at index H to level 6 child; level 6, has ptrs at indices # and R to leaves (HEARTH) and (HEARTHROB), respectively. 11 The hash values are: x || 60 | 30 | 20 | 95 | 35 | 70 | 25 --------------------------------------- h(x)|| 5 | 3 | 7 | 5 | 1 | 1 | 5 The table after the insertions: index | key | next ------+-----+----- 0 | 95 | 4 ------+-----+----- 1 | 35 | 2 ------+-----+----- 2 | 70 | ------+-----+----- 3 | 30 | ------+-----+----- 4 | 25 | ------+-----+----- 5 | 60 | 0 ------+-----+----- 6 | | ------+-----+----- 7 | 20 | ------+-----+----- 12 The table after the insertions, with replaced entries in ( ): index | Key ------+-------------------------- 0 | 40 ------+-------------------------- 1 | 91 ------+-------------------------- 2 | ------+-------------------------- 3 | ------+-------------------------- 4 | 60 ------+-------------------------- 5 |(75) (55) 35 ------+-------------------------- 6 | ------+-------------------------- 7 |(60) 55 ------+-------------------------- 8 | 28 ------+-------------------------- 9 | 75 ------+-------------------------- 13 The two middle pages are merged after the removal, and then the directory is halved. In the new directory: 00 pointer is to old top page (no change to the page); 01 pointer is to the merged page, which has depth 2 and contains the entries with keys hashing to 010001, 010010, and 011111; 10 and 11 pointers are both to old bottom page (no change to the page).