COMPUTER SCIENCE 3100 -- DATA STRUCTURES + ALGORITHMS Study Questions for the Second In-Term Exam ====================================================================== Chapter Five: Trees ====================================================================== What property or properties must a binary tree have in order to be a binary SEARCH tree? ====================================================================== Define the following traversal orders: InOrder, PreOrder, PostOrder, Level Order, Reverse Level Order ====================================================================== Give pseudo-code for a procedure (algortihm) that recursivley traverses a binary tree in pre-order. ====================================================================== Name and describe applications of each of the following kinds of traversal of a binary tree. In Order, Pre Order, Post Order, Level Order, Reverse In Order, Reverse Level Order. ====================================================================== List the letters in the nodes of the tree shown below in each of the following orders: a) PreOrder b) PostOrder c) InOrder Warning: The labels of the nodes have been chosen to be UNrelated to any of these orderings. T .. . . . . S Q .. .. . . . . . . . . H V C P . . . . . . K Y D .. . . . . U F ====================================================================== 32 .. . . . . . . 16 48 .. .. . . . . . . . . . . . . 8 24 40 56 . . . . . . 44 60 .. . . 58 62 The figure above depicts a binary search tree. Fill in the figure below to depict the tree after the operations shown are carried out. Assume the operations are carried out in the order shown, using the STANDARD ALGORITHMS explained in our text book. (Be especially careful to follow the standard when you delete a node with two children.) Where the tree below has spaces for nodes that do not exist, just leave the spaces blank. Insert 21, Insert 20, Insert 22, Delete 32, Delete 48, Delete 56 __ . . . . . . __ __ .. .. . . . . . . . . __ __ __ __ .. .. .. .. . . . . . . . . . . . . . . . . . . . . . . . . __ __ __ __ __ __ __ __ .. .. .. .. .. .. .. .. . . . . . . . . . . . . . . . . ====================================================================== Compute the average number of compares that would have to be done to do an unsuccessful search in the binary search tree below. 128 .. . . . . . . 64 192 . .. . . . . . . 32 180 224 .. . . . . . . . . . . 16 48 164 ====================================================================== Draw a picture of the tree that would result from doing a SINGLE LEFT rotation to the tree shown below. Assume that the node marked "B" is the pivot node. Be sure to label the subtrees T1, T2, and T3 in your picture. B .. . . . . . . . . . A ... . . . ... . . . . . . . . . T1 . . . . . . . ............... ... ... . . . . . . . . . . . . . T2 . . T3 . . . . . ............... ............... . . . N ====================================================================== Starting with an empty tree, show the results of doing each of the following insertions into an AVL tree: (Circle each part of your answer.) Insert 2, Insert 4, Insert 6, Insert 8, Insert 10, Insert 5. Also name, in the order done, the rotations you used to balance the tree. ====================================================================== 40 .. . . . . . . 20 60 .. .. . . . . . . . . 10 30 50 80 .. .. .. .. . . . . . . . . . . . . . . . . 05 15 25 35 45 55 70 100 The binary tree shown ABOVE can be transformed into a HEAP by applying the process of "heapification" that I discussed in class. (Stubbs and Webre call this the "heap construction process") Fill in the diagram BELOW to show what the resulting heap looks like after this process is carried out. You must use the ordering conventions used in class -- LARGER elements above, SMALLER elements below. __ .. . . . . . . __ __ .. .. . . . . . . . . __ __ __ __ .. .. .. .. . . . . . . . . . . . . . . . . __ __ __ __ __ __ __ __ ====================================================================== Chapter Six: Internal Sorting ====================================================================== Describe the "improvements" to quicksort that are discussed in Stubbs and Webre. ====================================================================== If there is a very large array of very large records to be sorted, what can be done to avoid moving the records from place to place in the array? Discuss all the important alternatives. ====================================================================== Describe the sorting tasks for which INSERTION sort is best suited. ====================================================================== Stubbs and Webre state that Radix sort is O( k * N ), where N is the number of items to be sorted. What is the quantity k? Can k be considered a constant, not depending at all on the value of N? Explain. ====================================================================== Describe the sorting tasks for which SELECTION sort is best suited. ====================================================================== For comparisons and data moves, state the average case and worst case "big-O" complexities of insertion sort, bubble sort, selection sort, quick sort, heap sort, merge sort, radix sort, and distribution sort. ====================================================================== Of heapsort, insertsort, mergesort, and quicksort, which is the all-round best performer, and why? ====================================================================== Chapter Seven: Sets (and Hashing) ====================================================================== Explain how bit maps can be used to implement sets and the following operations: member, union, intersection, and set difference. ====================================================================== What is the main reason for hashing? ====================================================================== Define "open addressing." ====================================================================== Name the properties that a good hashing function must have. ====================================================================== Describe two different commonly used hash functions. ====================================================================== Describe two different "collision resolution" strategies that can be used for hashing. ====================================================================== Explain why it would be a good idea to use a prime table size when hashing and using open addressing. ======================================================================