CSCE-5150 Analysis of Computer Algorithms
Homework 2
Question 1. (20 points)
What are the states of the queue after the following operations? Please specify the states at the
four labelled steps.
(Assume the queue is represented horizontal and the front pointer is at left as shown below).
1
1
Question 2. (30 points)
Insert 9, 7, 3, 1, 12, 8, 4, 3 (as you read them) into an originally empty min-heap. Show how the
heap looks like after each insertion in tree form. (Hint: the new number is inserted as the last
element in the tree).
Question 3. (25 points)
Suppose we have a sorted array and we wish to determine whether an item say with value v is in
the array or not. We could use standard binary search to solve this problem. But suppose our
objective is to return the values of all items m positions to the left and right of the found item v.
Example:
Input: array [1, 2, 3, 4, 5, 6, 7, 8], v = 5, m = 2
Output: [3, 4, 5, 6, 7]
a) What modification is required to the standard binary search algorithm to achieve this
objective?
b) Will this modification affect the time complexity of the search? Justify your answer.
Question 4. (25 points)
One possible way of modifying binary search is to divide a sorted array recursively into 4 parts
instead of two. We would refer to this as quarternary search:
a) Please justify what is the time complexity of quarternary search?
b) Please explain the similarity between quartenary search and binary search in terms of
time complexity.