Final Review

1 Final Exam (Out of 70) • Part A: Basic knowledge of data structures – 20 points – Mulple choice

• Part B: Applicaon, Comparison and Implementaon of the data structures – 20 points – Apply supported operaons (like find and insert) to data structures we have covered like: BST, AVL, RBTs, Mulway , Ternary Trie, B trees, skip lists. Also essenal concepts in Huffman codes

• Part C: Simulang algorithms and run me analysis – 15 points – Graph algorithms: BFS, DFS, Dijkstra, Prims’, Kruskals’. Also union find

• Part D: C++ and programming assignments – 15 points – Short answer

2

Final Exam Practice Questions CSE 100 (Fall 2014) CSE Department University of California, San Diego

Part A: The Basics

This section tests your basic knowledge of data structures via multiple choice questions. Sample questions include all the iclicker and reading quiz questions covered in class. Please make sure you review them.

Part B: Application, Comparison and Implementation

This section tests how well you understand what goes on under the hood of the data structures covered during the course, their strengths and weaknesses and their applications. The format is short answers and fill in the blanks.

1. B-trees.

(a) Construct a 2-3 by inserting the following keys in the order shown: 10, 15, 20, 25, 17, 30. You can check your answers and experiment with trees of your own design at the following web sites: https://www.cs.usfca.edu/˜galles/visualization/BTree.html B-trees http://ats.oka.nu/b-tree/b-tree.manual.html

(b) Which of the following are legal 2,3 trees (B tree of order 3)? For a tree that is not a valid 2,3 tree, state a reason why. 22 50 22 52

8 30 64 5 9 24 53 54

22 12 50 79

5 9 1 7 4 7 30 64 69 84 102

3 Insert the value 42 into the following BTree.

4 Ternary 5. Ternary search Trees.

(a) Consider the following ternary . Nodes with double circles have their end bits to true. Circle all of the words from the list on the right that are in the tree and write in any words that are missing. At the end you should have a complete list of all words found in the tree, and only those words. a n

l d s air, all, a, and, as i l t r

(b) Does the height of this tree depend on the order in which the keys have been inserted? (c) Briefly explain why you would prefer to use a ternary search tree rather than a to implement getAllValidWords() in PA4.

5 Part C: Simulating Algorithms and Run Time Analysis

This section tests how well you understand the algorithms during the course. The focus is on simulating well known graph algorithms and the application of data structures to achieve fast run times. You will also be tested on analyzing the running time of these algorithms. The format is short answers and fill in the blanks.

1. Graphs. Given the following graph, run Dijkstra’s algorithm on it, with source node A. Alongside the graph is the for eachWrite the sequence of verces visited when running DFS on the node that you will modify, see below. D following graph. Assume the link to the vertex with the A: dist = 0 prev= -1 done= f adj: ((B,5),(D,10),(E,6))

0 minimum edge weight is chosen when mulple choices are available B: dist = prev= -1 done= f adj: ((D,3)) C 3 4 1 10 C: dist = prev= -1 done= f adj: ((D,0))

B 1 E 1 D: dist = prev= -1 done= f adj: () 5 6 1 A E: dist = prev= -1 done= f adj: ((C,3)) Write the sequence of verces visited when running BFS on the following graph. Assume the link to the vertex with the 1 The boxes below represent the priority queue which is used in the algorithm. Each set of boxes represents the priority queue after the firstminimum edge weight is chosen when mulple choices are pair has been dequeued and its associated node has been fully expanded (i.e. its neighbors, along withavailable their distances, have been added to the priority queue as appropriate). You will fill these in. Run Dijkstra’s algorithm by (1) modifying the values in the dist, prev, done and done fields (above) as the algorithm runs, and (2) showing the values stored in the priority queue after each new node is expanded. For the data structures at the top, you should cross off old values as you replace them. For the priority queue, you should show the contents of the whole queue in the next set of boxes after you have fully expanded/explored from the node that you just removed from the front of the queue in the previous step. The initial priority queue and initial values are already filled in for you. You may stop the process when each node has been marked as done. You may not need all of the queues. If you do need more, just draw them in below the final array, to the side, or on the scratch page. 6 Which of the following are AVL trees?

B C 42 A 42 42 10 67 67 10 67 10

11 53 90 53 90 53 90

87 87

D. A&C E. A&B&C Annotate the trees with balance factors 7 AVL Rotaons 0

30 -1 1

15 70 0 0

20 60

Insert 50. Then insert 66. Draw the resulng AVL tree. 8 Red Black trees

30

15 70

20 60

How can we make the above tree a valid red-black tree

Insert 50. Then insert 66. Draw the resulng RBT. 9 Data structure Comparison

Insert Find Avg Worst Avg Worst Sorted array Sorted Linked list Queue Skip list BST AVL/RBT Min- B-trees

10 Data structure Comparison Which of the following pairs of data structures, which of the pair is the beer choice for.

• Inserng a list of sorted elements (worst case): A. AVL tree B. Binary search tree C. They are about equal

• In-order traversal of elements: A. Hashtable B. Binary search tree C. They are about equal

11 Data structure Comparison Which of the following pairs of data structures, which of the pair is the beer choice for.

• Smallest average-case (Big-O) me to find an element: A. Hashtable B. AVL tree C. They are about equal

• Fastest actual me to find an element from secondary storage (NOT big-O) A. RBT B. AVL tree C. B-trees D. They are all about equal

• Requires less space: A. Mul-way trie B. Ternary tree C. They are about equal 12 Some comic relief…

hp://xkcd.com/1185/

13 Some comic relief…

hp://xkcd.com/1185/14

Good luck with the final!

15