IS 320 FINAL Spring 2014 Turn in to [email protected] using your WOU email account only. Your finished exam must be returned by 1:00 pm Tuesday June 10th. Name________________ VNumber___________________ 1. In the linked-list version of the stack class, which operations require linear time for their worst-case behavior? A. is_empty B. peek (means look at top element) C. pop D. push E. None of these operations require linear time. 2. The operation for adding an entry to a stack is traditionally called: A. add B. append C. insert D. push 3. The operation for removing an entry from a stack is traditionally called: A. delete B. peek (means look at top element) C. pop D. remove 4. Which of the following stack operations could result in stack underflow? A. is_empty B. pop C. push D. Two or more of the above answers 1 5. In the array version of the stack class (with a fixed-sized array), which operations require linear time for their worst-case behavior? A. is_empty B. peek (means look at top element) C. pop D. push E. None of these operations require linear time. 6. One difference between a queue and a stack is: A. Queues require dynamic memory, but stacks do not. B. Stacks require dynamic memory, but queues do not. C. Queues use two ends of the structure; stacks use only one. D. Stacks use two ends of the structure, queues use only one. 7. If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed? ABCD ABDC DCAB DCBA 8. In the linked list implementation of the queue class, where does the push member function place the new entry on the linked list? A. At the head B. At the tail C. After all other entries that are greater than the new entry. D. After all other entries that are smaller than the new entry. 9. In the linked-list version of the queue class, which operations require linear time for their worst-case behavior? A. front B. push C. empty D. None of these operations require linear time. 2 10. I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer. Which of these pointers will change during an insertion into a NONEMPTY queue? A. Neither changes B. Only front_ptr changes. C. Only rear_ptr changes. D. Both change. 11. I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer. Which of these pointers will change during an insertion into an EMPTY queue? A. Neither changes B. Only front_ptr changes. C. Only rear_ptr changes. D. Both change. 12. Here is a small binary tree: 14 / \ 2 11 / \ / \ 3 10 30 / / 7 40 A. B. C. D. Circle all the leaves. Put a square box around the root. Draw a star around each ancestor of the node that contains 10. Put a big X through every descendant of the node that contains 10. 3 13. Draw a full binary tree with at least 6 nodes. 15. Draw a complete binary tree with exactly six nodes. Put a different value in each node. Then draw an array with six components and show where each of the six node values would be placed in the array (using the usual array representation of a complete binary tree). 14. 16. Here is a small binary tree: 14 / \ 11 / \ / \ 1 3 10 30 / / 7 40 2 17. Write the order of the nodes visited in: A. An in-order traversal: ______________________________ B. A pre-order traversal: ______________________________ C. A post-order traversal: ______________________________ 4 18. Using the tree above. What is the depth of the tree? A. 2 B. 3 C. 4 D. 8 E. 9 19. Using the tree above. How many children does the root have? A. 2 B. 4 C. 6 D. 8 E. 9 20. Using the tree above. Which statement is correct? A. The tree is neither complete nor full. B. The tree is complete but not full. C. The tree is full but not complete. D. The tree is both full and complete. 21. What is the minimum number of nodes in a full binary tree with depth 3? A. 3 B. 4 C. 8 D. 11 E. 15 22. What is the minimum number of nodes in a complete binary tree with depth 3? A. 3 B. 4 C. 8 D. 11 E. 15 5 23. Select the one true statement. A. Every binary tree is either complete or full. B. Every complete binary tree is also a full binary tree. C. Every full binary tree is also a complete binary tree. D. No binary tree is both complete and full. 24. Suppose T is a binary tree with 14 nodes. What is the minimum possible depth of T? A. 0 B. 3 C. 4 D. 5 25. Select the one FALSE statement about binary trees: A. Every binary tree has at least one node. B. Every non-empty tree has exactly one root node. C. Every node has at most two children. D. Every non-root node has exactly one parent. Consider this binary search tree: 14 / \ 2 11 / \ 10 30 / \ 1 3 \ 7 \ 40 26. Suppose we remove the root, replacing it with something from the left subtree. What will be the new root? A. B. C. D. E. 3 1 11 7 2 6 Here is an array of ten integers: 5 3 8 9 1 7 0 2 6 4 27. Draw this array after the FIRST iteration of the large loop in a selection sort (sorting from smallest to largest). Here is an array of ten integers: 5 3 8 9 1 7 0 2 6 4 28. Draw this array after the FIRST iteration of the large loop in an insertion sort (sorting from smallest to largest). This iteration has shifted at least one item in the array! Here is an array which has just been partitioned by the first step of quicksort: 3, 0, 2, 4, 5, 8, 7, 6, 9 29. Which of these elements could be the pivot? (There may be more than one possibility!) 30. Give a concise accurate description of a good way for quicksort to choose a pivot element. Your approach should be better than "use the entry at location [0]". 31. Give a concise accurate description of a good way for quicksort to improve its performance by using insertionsort. 7 32. Fill in the following table for the times to sort an array of n items. Use only big- O notation, and do not have any extraneous constants in your expressions. Binary search of a sorted array Insertion sort Merge sort Quick sort without "median of three" pivot selection Quick sort with "median of three" pivot selection Average Case . . _______ . . _______ . . _______ . . _______ . . _______ Selection sort Heap sort . . _______ . . _______ 33. Suppose that a selectionsort of 100 items has completed 42 iterations of the main loop. How many items are now guaranteed to be in their final spot (never to be moved again)? A. 21 B. 41 C. 42 D. 43 Suppose we are sorting an array of ten integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: 1 2 3 4 5 0 6 7 8 9 34. Which statement is correct? (Note: Our selectionsort picks largest items first.) A. The algorithm might be either selectionsort or insertionsort. B. The algorithm might be selectionsort, but could not be insertionsort. C. The algorithm might be insertionsort, but could not be selectionsort. D. The algorithm is neither selectionsort nor insertionsort. 8 Suppose we are sorting an array of eight integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: 1 4 5 7 8 1 3 6 35. Which statement is correct? (Note: Our selectionsort picks largest items first.) A. The algorithm might be either selectionsort or insertionsort. B. The algorithm might be selectionsort, but it is not insertionsort. C. The algorithm is not selectionsort, but it might be insertionsort. D. The algorithm is neither selectionsort nor insertionsort. 36. Draw the directed graph that corresponds to this adjacency matrix: 0 1 2 3 | | | | 0 true true false true 1 false false false false 2 true false false true 3 false false true false | | | | The number of distinct minimum spanning trees for the weighted graph below is 9 Figure 6 shows this problem depicted as a graph. Each node is a house, and the edges are the means by which one house can be wired up to another. The weights of the edges dictate the distance between the homes. Your task is to wire up all ten houses using the least amount of telephone wiring possible. Show the graph solution below. Answer: 10 Imagine, however, that you are not one of those people. Instead, you are someone who values his money much more than his time, and are most interested in finding thecheapest route, regardless of the number of connections. This might mean flying from New York to Miami, then Miami to Dallas, then Dallas to Phoenix, Phoenix to San Diego, and finally San Diego to L.A. We can solve this problem by modeling the available flights and their costs as a directed, weighted graph. Figure 10 shows such a graph. Figure 10. Modeling of available flights based on cost Find the cheapest path from NewYork to Los Angeles. =$___________, cities visited ___________________________________ Eulerian Cycle An undirected graph has Eulerian cycle if following two conditions are true. ….a) ….b) Eulerian Path An undirected graph has Eulerian Path if following two conditions are true. ….a) ….b) 11 Does Graph I have an Euler circuit? an Hamiltonian circuit? Does Graph II have an Euler circuit? an Hamiltonian circuit? 12 Sorting (use some of the above results) Algorithm Data Structure Quiksort Array Mergesort Array Heapsort Array Bubble Sort Array Time Complexity Best Average Worst O(n) O(n^2) O(n^2) EXAMPLE EXAMPLE Insertion Sort Array Selection Sort Array Bucket Sort Array Radix Sort Array 13

Download
# IS 320 FINAL Spring 2014