Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
136 views2 pages

Queue and Heap Operations Analysis

This document contains 4 questions about algorithms: 1) A queue operations problem asking for the state of the queue after given operations. 2) An insertion problem asking to show the min-heap structure after inserting numbers. 3) A binary search problem asking how to modify it to return values around a found item and if it affects complexity. 4) A question about quarternary search asking its time complexity and similarity to binary search.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views2 pages

Queue and Heap Operations Analysis

This document contains 4 questions about algorithms: 1) A queue operations problem asking for the state of the queue after given operations. 2) An insertion problem asking to show the min-heap structure after inserting numbers. 3) A binary search problem asking how to modify it to return values around a found item and if it affects complexity. 4) A question about quarternary search asking its time complexity and similarity to binary search.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

You might also like