Homework #5
Due Date:
Monday
, November 8th, start of class
Please note the Monday due date.
1. We are given a sorted array
A
[1
..n
], composed of
distinct
integers (the values can be neg
ative). We want to determine if there is an index
i
such that
A
[
i
] =
i
. Give an
O
(log
n
)
algorithm to solve this problem, and justify its correctness.
2. Suppose we’d like to implement a sorting variant where
every element
is compared only a
small number of times. Note that while Merge Sort has
O
(
n
log
n
) comparisons, a particular
element may be compared
n
or more times.
(a) Devise a divideandconquer algorithm to merge two sorted arrays of length
n
, which
guarantees that
every element
is included in at most
O
(log
n
) comparisons.
Hint: Use
binary search to locate the median of one array in the other.
(b) Using this modiﬁed Merge, prove that MergeSort will include each element in at most
O
(log
2
n
) comparisons.
3. You are given an array
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 12/13/2010 for the course CSCI 570 at USC.
 '06
 Shamsian
 Algorithms, Sort

Click to edit the document details