COMPUTER SCIENCE 3100 -- DATA STRUCTURES + ALGORITHMS Study Questions for the Final of December 17, 1997 ====================================================================== Chapter One: Introduction ====================================================================== Define the following: Data Type Data Structure Abstract Data Structure Native Data Type Atomic Data Type Information Hiding ====================================================================== Name some of the advantages of abstract data typing and information hiding. ====================================================================== Chapter Two: Arrays, Records, and Simple Linked Lists ====================================================================== What is an array mapping function? What is it used for? Explain its importance to implementing the array as an abstract data structure. ====================================================================== Certain information, often stored in a small table, is used in connection with implementing RECORD data structures to access the respective FIELDs within the RECORD. What information is this? ====================================================================== Give a definition of the abstract data type "pointer". ====================================================================== What is "dynamic memory allocation"? How does it work? ====================================================================== Chapter Three: Stacks and Queues ====================================================================== Give a definition of a priority queue. ====================================================================== Explain how stacks and queues can be viewed as special cases of a priority queue. ====================================================================== What are the disadvantages to implementing a stack as an array? ====================================================================== What are the disadvantages of the linked implementation of a stack in comparison with the array implementation? ====================================================================== What are the disadvantages of the array implementation of a priority queue which do NOT arise in connection with the array implementations of stacks and queues in our text? ====================================================================== Our text discusses ways of implementing STACKS, QUEUES, and PRIORITY QUEUES as ARRAYS. What operation(s) of the priority queue described are O(N)? Explain WHY each operation you mention is O(N). ====================================================================== In the discussion of priority queues in our text, it is mentioned that there is an operation on a priority queue containing N elements that can be done in O(log N) time for the array implementation, but takes O(N) time for the linked implementation. What is that operation, and what is the algorithm that makes it so quick in an array? ====================================================================== Chapter Four: Linear Structures ====================================================================== Stubbs and Webre discuss FIVE operations associated with an ABSTRACT LIST that have DIFFERENT "big O" COMPLEXITY depending on whether the list is implemented as an array or a linked list. Name as many of the five as you can remember, together with their "big O" complexity in each implementation. Clearly label all parts of your answer. (Assume the array and linked list implementations are the ones described in our text. ====================================================================== Derive mathematically the expression for the expected number of probes when doing a successful sequential search in an unordered list of size N. Assume all keys are equally likely. ====================================================================== What is sentinel search? What are its advantages? ====================================================================== What is a chronologically ordered list? ====================================================================== What is a frequency ordered list? ====================================================================== If a frequency ordered list contains 5 elements with frequencies 25, 15, 5, 3, and 2, then what is the expected number of probes when a successful search is done? ====================================================================== What is a self-organizing list? ====================================================================== What is interpolation search? Is interpolation search superior to binary search? In what way? ====================================================================== 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 (algorithm) 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) ====================================================================== 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. ====================================================================== Chapter Eight: Strings ====================================================================== Describe several ways of representing strings as Pacal or C data structures. ====================================================================== Define "fixed length" character representation. ====================================================================== Starting with a list L of frequencies, draw a Huffman coding tree that represents a Huffman code for L. ====================================================================== Explain what the "obvious" string matching algorithm is. ====================================================================== Chapter Nine: Graphs ====================================================================== Discuss ways that directed or undirected graphs can be represented by adjaceny lists or adjacency matrices, especially the representations from Stubbs and Webre. ====================================================================== Given information about a specific graph and/or a specific graph operation, discuss the choice of representation of the graph that would tend to make the operation most efficient. (For example, the relative number of nodes and edges in a graph can make a difference in the ways that are convenient to represent it.) ====================================================================== Given a drawing of a graph and some information about the order in which one generates the neighbors of a node, mark the nodes according to the order they would be visited in a depth-first search or a breadth-first search. ====================================================================== Similar to the previous problem, given a drawing of a network, list in order the edges that might be chosen to generate a minimal cost spanning tree using the algorithm of chapter 9 of Stubbs and Webre. ======================================================================