# Sample1 - CSE 830 Design and Theory of Algorithms Sample...

This preview shows pages 1–3. Sign up to view the full content.

CSE 830: Design and Theory of Algorithms Sample Exam I Questions I. Problem Complexity and Asymptotic (Big-Oh) Notation 1. For each of the following, compute how large of a problem instance you need before algorithm A is faster than algorithm B? How much time do the algorithms take on that instance? (a) Algorithm A takes n 2 days to solve a problem of size n . Algorithm B takes n 3 seconds on the same problem. (b) Algorithm A takes n 2 days to solve a problem of size n . Algorithm B takes 2 n seconds on the same problem. 2. Prove or find a counter-example: if f ( n ) = O( F ( n )) and g ( n ) = O( G ( n )) then f ( n ) + g ( n ) = O( F ( n ) + G ( n ) ). 3. Insertion sort takes one second to sort 1000 items (worst-case time) on a particular computer. Estimate the amount of time it would take to sort 100,000 items. If Quicksort took 1 second for 1000 items, how long would you expect it to take for 1,000,000? 4. List the functions below from the lowest to the highest order. If any two or more are of the same order, indicate which. n n log n 2 n ln n n n 3 + 7 n 5 log n sqrt( n ) e n n 2 + log n n 2 2 n -1 log log n n 3 (log n ) 2 n ! n 1+ ε (where 0< ε <1) II. Data Structures and Data Types 5. A deque (Double Ended QUEue) is a container type that is more flexible than either a stack or a queue -- you can insert or remove data from either end. If you needed to implement a deque using only two of the simpler container types, which would be fastest: 2 stacks, 2 queues, or 1 stack and 1 queue? Describe your implementation and give the time complexity for InsertFront, RemoveFront, InsertTail, and RemoveTail. 6. List the three rules that define the structure of a heap. 7. Show how to implement a standard first-in, first-out queue using only a heap as the underlying data structure. What is the run time for inserting and removing items from such a queue?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8. Draw a heap for the key values 2, 14, 10, 23, 8, 3, 12, 20, 1 and 17. Draw what this heap would look like after an “Extract-Max” is run on it. 9. Given a hash table with 100 bins and a good hashing function, what is the probability that the first two entries end up in different bins? If there were three entries, what is the probability that they all end up in different bins? III. Recursion 10. Convert the following to iterative (non-recursive) functions: (a) f(n) if (n == 1) return 1 else return f(n-1) + 1 (b) f(n) if (n == 1) return 1 else return f(n-1) * 2 (c) f(n) if (n == 1) return 1 else return f( floor(n/2) ) + 1 (d) f(n) if (n == 1) return 1 else return f( floor(n/2) ) * n 11. Find the rate of growth of the following recurrence relations using recursion trees: (a) T(n) = T( α n) + T((1 - α ) n) + n, where 0 < α < 1. (b)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 07/25/2008 for the course CSE 830 taught by Professor Ofria during the Spring '08 term at Michigan State University.

### Page1 / 6

Sample1 - CSE 830 Design and Theory of Algorithms Sample...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online