Analysis of Algorithms, 91 s3

Analysis of Algorithms, 91 s3

<p>UML CS 91.404 Final Exam Fall, 2004</p><p>NAME:______</p><p>FINAL EXAM</p><p>This exam is open books, notes and closed neighbors, calculators</p><p>The upper bound on exam time is 2.5 hours.</p><p>Please put all your work on the exam paper.</p><p>(Partial credit will only be given if your work is shown.)</p><p>Good luck!</p><p>PLEASE REMEMBER TO FILL OUT AN ON-LINE COURSE EVALUATION at http://teaching.cs.uml.edu/evaluations</p><p>1 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p>1: (8 points) Function Order of Growth</p><p>(a) (4 points) List the 3 functions below in nondecreasing asymptotic order of growth:</p><p> nlg n nlg4 n 32 log9 n </p><p>1) 2) 3)</p><p> smallest largest</p><p>Given: </p><p>2 log9 n 4 1) f1(n)  nlgn 2) f2 (n)  3  3) f3 (n)  O(nlg n)</p><p>Circle TRUE or FALSE for each statement below & briefly justify your choice.</p><p>(b) (2 points) f2 (n)  ( f3 (n))</p><p>TRUE FALSE</p><p>(c) (2 points) f2 (n)  O( f1(n))</p><p>TRUE FALSE</p><p>2 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p>2: (6 points) Recurrence </p><p>Find a tight upper and lower bound on the closed-form solution for the following recurrence:</p><p> 3    n     17T   5n 2  n  k T(n)    4      (1) n  k where k is a small integer. That is, find a function g(n) such that T(n)  (g(n)) . </p><p>3 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p>3: (10 points) Sorting</p><p>Algorithm HYBRID below is a variation on BUCKET-SORT that calls COUNTING-SORT.</p><p>The algorithm’s inputs are: - An array A of integers; - The number of buckets b; - An integer parameter c.</p><p>HYBRID(A,b,c) for i  1 to length[A] do A[i]  A[i]modc for i  0 to b 1 do for j  1 to length[A] do B[i][ j]  0 BNum[i]  0 for i  1 to length[A] do r  (RANDOM (0,32768))modb BNum[r]  BNum[r]1 B[r][BNum[r]]  A[i] for i  0 to b 1 ▷Pass row i of B to COUNTING-SORT and store sorted result D back into row i of B. do B[i]  COUNTING  SORT(B[i], D, ______)</p><p> a) (6 points) Fill in the blank for what should be passed as the third argument to COUNTING-SORT and briefly explain your choice. If there is no legal choice, say so and explain why.</p><p>4 of 15 UML CS 91.404 Final Exam Fall, 2004 b) (4 points) Does the pseudocode resulting from (a) with the blank filled in cause the entries of A to appear in B in nondecreasing order? Briefly explain your reasoning.</p><p>5 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p>4: (14 points) Red-Black Trees</p><p>Define a 3-red-black tree to be a red-black tree in which property (4) is modified as follows:</p><p>Instead of “if a node is red, then both its children are black”, it is “if a node is red and its parent is red, then both of its children are black.”</p><p>Consider the impact of this change. In particular, recall that Lemma 13.1 holds for red-black trees:</p><p>Lemma 13.1: A red-black tree with n internal nodes has height at most 2lg(n+1).</p><p>Is Lemma 13.1 true for a 3-red-black tree?</p><p>Circle YES or NO & justify your choice.</p><p>YES NO</p><p>6 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p> this page intentionally left blank for work</p><p>7 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p>5: (10 points) Hash Tables </p><p>MysteryHash(k,m) if k  m then return k   k   else return MysteryHash  ,m  m </p><p>(6 points) Circle the bound that best describes the worst-case asymptotic running time of MysteryHash and briefly justify your choice:</p><p>(a) (k) (b) (m) (c) (km) </p><p>(d) (lgk) (e) (lgm) (f) (k2)</p><p>(g) (m2) (h) (klgk) (i) (klgm)</p><p>(j) None of the above running times is a valid bound.</p><p>8 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p>(4 points) Can MysteryHash be used as a hash function for a hash table with m slots? </p><p>Circle YES or NO & briefly justify your choice.</p><p>YES NO</p><p>9 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p>6: (6 points) Shortest Paths</p><p>In order to find the shortest path in the graph below from vertex A to vertex F, which of the algorithms listed below solves the problem using the smallest worst-case asymptotic running time?</p><p>4 4 B E A 4 4 4 4 D 4 4 4 F C 4 (Assume an adjacency list representation of the graph.)</p><p>Circle one choice below. Briefly justify your answer. a) DIJKSTRA b) MST-PRIM c) BFS d) MST-KRUSKAL e) DFS f) TOPOLOGICAL-SORT g) None of the above algorithms can solve the problem</p><p>10 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p>7: (6 points) Data Structures</p><p>Consider the following task for a collection C of items in which each item has a key value and satellite data. The task is to make many repetitions of a call to an operation DeleteAll. DeleteAll accepts, as inputs, the collection C plus two key values k1 and k2. DeleteAll(C, k1, k2) deletes from C all items whose key values are in between k1 and k2 (inclusive). It returns a list of the items that are deleted. </p><p>Assume that: - each key value is an integer; - there is a total ordering defined on the key values; - satellite data for each item consists of 5 integer values.</p><p>In the list below, circle the representation of C that allows the entire task (including all repetitions) to be accomplished with the smallest worst-case asymptotic running time, while only using an amount of storage that is linear in the number of elements in the collection. </p><p>Circle one choice below. Justify your answer. a) STACK b) QUEUE c) LINKED LIST (singly linked) d) BINARY SEARCH TREE e) RED-BLACK TREE f) LINKED LIST (doubly linked) g) HASH TABLE h) HEAP (using array implementation) i) None of the above data structures can solve the problem.</p><p>11 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p>8: (40 points) Design an Algorithm: </p><p>Given a Binary Search Tree T and a key value k, design an algorithm to efficiently locate and return all the records with key value equal to k. (Note that you will need to select an appropriate data structure for storing the records.)</p><p>The next 3 pages ask you to provide pseudocode, correctness justification and an upper bound on the worst-case asymptotic running time.</p><p>12 of 15 UML CS 91.404 Final Exam Fall, 2004</p><p> a) (13 points) Pseudocode. </p><p>13 of 15 UML CS 91.404 Final Exam Fall, 2004 b) (13 points) Correctness. </p><p>14 of 15 UML CS 91.404 Final Exam Fall, 2004 c) (14 points) Analysis: Provide as tight an upper bound on the worst- case asymptotic running time as you can. </p><p>Hint: You might want to express the running time as a function of the height h of the tree and the number of records found that have key values equal to k.</p><p>15 of 15</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    15 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us