




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The instructions and problems for a midterm exam in the computer science course cmsc 420, focusing on algorithm analysis and data structures. The exam includes questions on big o notation, worst-case and best-case analysis of algorithms, tridiagonal matrices, ternary trees, and dictionary ordering. Students are allowed open books and notes during the exam.
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Instructions:
Problem 1. Professor Prune has created an algorithm that does some kind of computation on an array. If the algorithm is called on an array of size n, then the number of comparison operations done by the algorithm will vary depending on which array of size n, but it will always be a number in the interval from 2n^2 − n to n^3 + 2n − 1, inclusive.
Cbest(n) = O(n^2 ) Cbest(n) = Ω(n^2 ) Cbest(n) = Θ(n^2 )
Cbest(n) = O(n^2 lg n) Cbest(n) = Ω(n^2 lg n) Cbest(n) = Θ(n^2 lg n)
Cbest(n) = O(n^3 ) Cbest(n) = Ω(n^3 ) Cbest(n) = Θ(n^3 )
Cworst(n) = O(n^2 ) Cworst(n) = Ω(n^2 ) Cworst(n) = Θ(n^2 )
Cworst(n) = O(n^2 lg n) Cworst(n) = Ω(n^2 lg n) Cworst(n) = Θ(n^2 lg n)
Cworst(n) = O(n^3 ) Cworst(n) = Ω(n^3 ) Cworst(n) = Θ(n^3 )
Problem 2. A tridiagonal matrix is a square matrix T [1..n, 1 ..n] in which T [i, j] is nonzero only if |i − j| ≤ 1. You are to develop a sequential storage allocation strategy for tridiagonal matrices that only allocates storage to the nonzero entries.
Problem 3. A ternary tree is like a binary tree, except that each node p has three children: left(p), middle(p), and right(p).
Problem 4. Suppose a dictionary has n elements whose keys are K 1 , K 2 ,... , Kn. Suppose that for each LookU p operation, the argument is Ki with probability 1/ 2 i. Then the optimal ordering for the keys is K 1 , K 2 ,... , Kn. Let Copt(n) be the expected number of comparisons for a successful search if the keys are stored in that order.
Problem 4.
Problem 5. Consider a target string that contains 200 occurrences of the character A, followed by the characters ABABA. Suppose we are searching for ABABA.
Problem 5. Professor Prune says, “Another way to do range searching is to use a binary search tree that is threaded. This way, if want to find all of the nodes in some range, then you only need to search for the first node in the range. Once you have found this node, you can follow the threads to find all of the other nodes in the range.”