Docsity

C343 Final Exam Questions and Answers - Data Structures and Algorithms, Exams of Data Structures and Algorithms

Partial preview of the text

Download C343 Final Exam Questions and Answers - Data Structures and Algorithms and more Exams Data Structures and Algorithms in PDF only on Docsity!

Spring 2008 C343 Final Name:

Question 1a. (10 points) Show the AVL trees (plural) that result from inserting the keys 186, 039, 991, 336, 778, 066, 564, 154, 538, and 645 into an initially empty tree. Question 1b. (5 points) Show the result of deleting the key 186 from the tree in part a. Question 2. (10 points) Show that any n-node binary tree can be converted into any other using at most 2n rotations.

Question 3. (20 points) Find the approximate growth rates of the function f for each of the following recursively defined functions. In each case, assume that f(1) = 1. Don't simply guess; show your work. a. f(n) = f(n-1) + n- 1 b. f(n) = f(n/2) + 1 c. f(n) = 2f(n/2) + 1 d. f(n) = 2f(n/2) + n/ Question 4. (1 5 points) Interviewing at a data mining company, a nameless job applicant once faced the following question. Suppose that you have a very large file containing a random series of lowercase English words, one per line. You have been ordered to count how many times each word appears in the file and display the results (in no particular order) to your pointy-haired boss. You have as much RAM as necessary to do the job, but you may only read through the file ONCE. Describe an algorithm to perform this task Explain what data structure(s) you will need and why your choice is the best possible.

Question 7. (15 points) When designing heap sort, there are two natural ways to build a heap of n items starting from n unrelated items:

  1. Build a heap of 1 item, and then add n-1 items to the current heap incrementally. 2 ) Assume you have two heaps, each of size n/2. Then add a new item and build a new heap made of the new item plus the two sub-heaps. Ignoring small differences, like the difference between n/2 and (n+1)/2 depending on whether n is even or odd, analyze the above two ways to build a heap. Decide which way is more efficient in terms of comparisons between items in the worst case.