CS 361 FINAL EXAM Name______________________________________________ Spring 2008 Due in class(hard copy) Monday, April 28th 2008. All questions are worth 10 points. (1). Assume that you have a singly linked list with a dummy head node and that all the elements in the list(integers) are in sorted order. Write a function that removes any duplicate nodes from the list. Put your answer on the back of this page. (2). Assume that you have an EMPTY binary search tree, "T", which is implemented using a struct with pointers left & right and int element. What is the output of function "traverse" below if the following data is first inserted into the tree in the order given and no external balancing routines are called? data: 5, 6, 2, 8, 1, 3, 4 void traverse ( T SEARCH_TREE ); { if ( T != NULL ) { cout << T->element; traverse ( T->left ); traverse ( T->right ); }; } (3). Suppose we wanted to implement binary trees using a language that had pointers but did not allow recursion. Briefly describe two approaches to creating traversal routines in such a system. (4). Consider the array implementation of priority queues. What is the main advantage of the array implementation? Main disadvantage? (5). For internal sorting the quicksort is prefered over the mergesort. Why? What type of structures would make the mergesort more attractive? (6). Assume that you are working in the census dept. of a small town where the number of records is small enough for internal sorting. Fields in the records contain names and state of birth (i.e. Virginia ) among other things. You wish to produce a list sorted by state of birth and then by name within that state grouping. How would you attack the problem if you were not allowed to break the records into distinct smaller groups? Could you use quicksort? (7). Hashing is a technique to translate element unique identifiers into an ordered set of integers that can be used as the index values of a hash table structure. Describe three methods of handling hashing collisions. (8). Assume we have a singly linked list WITHOUT a dummy head node and the list is accessed through the head pointer "head". What happens to the list if head is passed to the following procedure? What is the "Big O" of this procedure? void unknown ( h & node_ptr ); node_ptr p, q, r; { p = h; q = NULL; while ( p != NULL ) { r = q; q = p; p = p->next; q->next = r; }; h = q; } (9). Consider a linked list implementation of a queue with a dummy head node and "front" and "rear" pointers. Conceptually, what would we have to do (including modifying the node structure) to the queue layout so that only one pointer is needed to access both the front and rear of the queue in O ( 1 ) time? Hint: do you need to be able to move both ways in the list? (10). Assume that you have a number of records that you want sorted by a certain key whose only possible values are "false" and "true". Using only constant extra space ( extra space is not proportional to n ), DESCRIBE an algorithm that will perform the sort in O(n) time.