This preview shows page 1. Sign up to view the full content.
McGill University COMP251: Assignment 2
Worth 10%. Due October 1 at the beginning of lecture (10am)
Question 1
Suppose
A
is already sorted in increasing order. Prove that the running time of
Quicksort on input
A
is Ω(
n
2
).
Question 2
Consider the following problem:
Input
: An array
A
[1
,
2
, . . . , n
] of distinct integers.
Output
: The number of pairs (
i, j
) such that
i < j
and
A
[
i
]
< A
[
j
] (i.e., the number of pairs
of elements in
A
that are in sorted order).
For example, on input
A
= (1
,
5
,
3
,
7
,
2) the output is 6 (the pairs are (1
,
2), (1
,
3), (1
,
4), (1
,
5),
(2
,
4), (3
,
4)).
(a) Suppose that
A
is in increasing order. What is the output?
(b) Now design a algorithm that solves the problem using divideandconquer technique. Your
algorithm must run in time
O
(
n
ln
n
). (Hint: Review the Mergesort algorithm.)
(c) Use the Master Theorem to verify that the running time of your algorithm is
O
(
n
ln
n
).
Question 3
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 11/05/2009 for the course COMP COMP 251 taught by Professor Phuongnguyen during the Fall '09 term at McGill.
 Fall '09
 PhuongNguyen
 Algorithms, Data Structures, Sort

Click to edit the document details