{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# a2 - McGill University COMP251 Assignment 2 Worth 10 Due...

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 divide-and-conquer 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 A ternary heap is like a (binary) heap that we discuss in lecture, but (with one possible exception) non-leaf nodes have 3 children instead of 2 children.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern