Final Review Announcements
Total Page:16
File Type:pdf, Size:1020Kb
Final Review Announcements • PA4 is due tonight at 11pm • PA3 re-grade requests due by Monday • Study guide and pracAce final posted on course website (website was upgraded to be mobile friendly). • Review session tomorrow from noon to 1pm • SecAon A: If you have mulAple finals (three or more) on Friday and need to take the exam on Wed, send me an email (with the necessary proof). • SecAon B: If you have mulAple finals (three or more) on Wed and need to take the exam on Friday, please respond to my Piazza poll Final Exam… • 4 Parts • Part 1: Basic knowledge of data structures and C++ – 20% to 30% of final score – MulAple choice • Part 2: Applicaon, Comparison and Implementaon of the data structures – 20% to 30% of final score – Short answers • Part 3: Simulang algorithms and run Ame analysis – 20% to 30% of final score – Short answers • Part 4: C++ and programming assignments 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 tree 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/Part 2: B-trees ˜galles/visualization/BTree.html 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 Insert the value 42 into the following BTree. 4. Consider the following set of initially unrelated elements is S=0,1,2,3,4,5,6, 7, 8, 9, 10, 11, 12. Assume that the initial union-find data structure is shown here, a forest of 12 singleton nodes with the header array initialized as shown. 0 1 2 3 4 5 6 7 8 9 10 11 12 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 4. Consider the following set of initially unrelated elements is S=0,1,2,3,4,5,6, 7, 8, 9, 10, 11, 12. Assume(a) Draw that the the final initial forest union-find of up-trees that data results structure from the is following shown here, sequence a forest of operations of 12 singleton using union- nodes with the headerby-size. array initialized Break ties by as keeping shown. the first argument as the root. Union(0,2), Union(3,4), Union(9,7), Union(9,3), Union (6,8), Union(6,0), Union(12,6), Union(1,11), Union(9,6) 0 1 2 3 4 5 6 7 8 9 10 11 12 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 (a) Draw the final forest of up-trees that results from the following sequence of operations using union- by-size. Break ties by keeping the first argument as the root. Union(0,2), Union(3,4), Union(9,7), Union(9,3), Union (6,8), Union(6,0), Union(12,6), Union(1,11), Union(9,6) (b) Draw the new forest of up-trees that results from doing a Find(4) with path compression on your forest of up-trees from (a). (b) Draw the new forest of up-trees that results from doing a Find(4) with path compression on your forest of up-trees from (a). 4. Consider the following set of initially unrelated elements is S=0,1,2,3,4,5,6, 7, 8, 9, 10, 11, 12. Assume that the initial union-find data structure is shown here, a forest of 12 singleton nodes with the header array initialized as shown. 0 1 2 3 4 5 6 7 8 9 10 11 12 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 (a) Draw the final forest of up-trees that results from the following sequence of operations using union- by-size. Break ties by keeping the first argument as the root. Union(0,2), Union(3,4), Union(9,7), Union(9,3), Union (6,8), Union(6,0), Union(12,6), Union(1,11), Union(9,6) (b) Draw the new forest of up-trees that results from doing a Find(4) with path compression on your forest of up-trees from (a). 6 9 8 12 0 3 7 2 4 1 11 Ternary Tries 5. Ternary search Trees. (a) Consider the following ternary search tree. Nodes with double circles have their end bits set 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 binary search tree to implement getAllValidWords() in PA4. Part C: SimulatingPartPart C: C: Simulating Simulating Algorithms Algorithms Algorithms and Run and Time and Run AnalysisRun Time Time Analysis Analysis Part C: Simulating AlgorithmsPartPart C: C: Simulating Simulating and Run Algorithms Algorithms Time and Analysis and Run Run Time Time Analysis Analysis This sectionThisThis tests section howsection tests well tests how you how well understand well you understand you the understand algorithms the algorithms the during algorithms the during course. during the course. The the focus course. The is focus on The simulating is focus on simulating is on simulating This section tests how wellThis you section understand tests how the well algorithms you understand during the algorithms the course. during The the focus course. is The on focus simulating is on simulating well knownwell graph known algorithms graph algorithms and theThis application and section the tests application of how data well structures of you data understand structures to achieve the algorithms to achieve fast run during fast times. run the course. times.You will The You also focus will is also on simulating well knownwell known graph graph algorithms algorithmswell and known the graph and application the algorithms application of and data the structuresapplication of data structures of to data achieve structures to fast achieve to run achieve times. fast fast run You run times. times. will also You You will will also also be tested onbe testedanalyzing on analyzing the running thewell timerunning known of these time graph of algorithms. algorithms these algorithms. and The the application format The isformat of short data structures is answers short to answers achieve and fill fast and in run fillthe times. in the You will also be testedbe tested on analyzing on analyzing thebe running testedbe the tested running on time analyzingon analyzing of time these the the runningof algorithms. running these time algorithms. time of these The of these algorithms. format algorithms. The is format short The The format answers is format short is short is and short answers answers fill answers in and and the and fill fill in fill the in in the blanks. blanks. blanks.blanks. blanks.blanks. 1. Graphs.1. GivenGraphs. theGiven following the following graph, run graph, Dijkstra’s run Dijkstra’s algorithm algorithm on it, with on it, source with nodesourceA node. AlongsideA. Alongside the the 1. Graphs.1. Graphs.GivenGiven the following the1. Graphs. following1. Graphs. graph,GivenGiven rungraph, the Dijkstra’s the following run following Dijkstra’s graph, algorithm graph, run run algorithmDijkstra’s on Dijkstra’s it, withalgorithm on algorithm source it, on with it, on node with it, source with sourceA. source Alongside node node nodeA.. AlongsideA Alongside the. Alongside the the graph is thegraph data is structure the data structurefor each node for each that node you that will you modify, will modify,see below. see below. graphgraph is the data is the structure data structuregraph forgraph each is the for is node the data each data structure that node structure you for that will eachfor you each modify, node willnode that see thatmodify, you below. you will will modify, see modify, below. see below.see below. D A: dist =A: 0 dist prev= = 0 -1 prev=A: done= dist -1 = 0 f done= prev=adj: f ((B,5),(D,10),(E,6)) -1 adj: done= ((B,5),(D,10),(E,6)) f adj: ((B,5),(D,10),(E,6)) D D D D D A: dist =A: 0 dist prev= = 0 -1A: prev= dist done= = 0 -1 f prev= done= adj: -1 ((B,5),(D,10),(E,6)) done=f adj: f ((B,5),(D,10),(E,6)) adj: ((B,5),(D,10),(E,6)) 0 0 0 0 0 0 B: dist =B: distprev= = -1prev= done= -1 f done= adj: f ((D,3)) adj: ((D,3)) B: dist =B: distprev= = B: dist -1B:prev= dist = done= = prev= -1 fprev= done= -1 adj: -1 done= ((D,3)) done=f f adj: adj: f ((D,3)) adj: ((D,3)) ((D,3)) C C C C 3 3 C C 3 3 3 3 1 1 1 4 4 14 4 1 10 4 1 10 10 410 10C: distC: =C: dist dist =prev= = prev= -1prev=C: done= dist -1C: -1 dist = done= f done== prev= adj: fprev= f ((D,0)) -1 adj: adj: -1 done= ((D,0)) ((D,0)) done= f adj: f adj: ((D,0)) ((D,0)) 10 C: dist = prev= -1 done= f adj: ((D,0)) B E B B B E B E E 1 E 11 1 1 B E 1 D: dist = prev= -1 done= f adj: () 5 D: distD: =D: dist dist =prev= = prev= -1prev=D: done= dist-1 -1 = done= f done=prev= adj: f f () -1 adj: adj: done= () () f adj: () 5 5 5 5 D: dist = prev= -1 done= f adj: () 5 6 6 6 6 6 1 6 11 1 A 1 E: dist = prev= -1 done= f adj: ((C,3)) A A A A E: distE: =E: dist dist =prev= = prev= -1prev=1E: done= dist -1 -1 = done= f done=prev= adj: f f ((C,3)) -1 adj: adj: done= ((C,3)) ((C,3)) f adj: ((C,3)) A E: dist = prev= -1 done= f adj: ((C,3)) 1 (A,0) The boxes below represent1 the priority11 queue which1 is used in the algorithm.