Lecture 22 - Probabilistic Analysis Flashcards

1
Q

What’s the worst case partition of quick sort? In words first, then derive it from T(n).

A
Split off a single element at each level.
T(n) = T(n-1) + T(0) + PartitionTime(n)
=  T(n – 1) + Q(n)
= sum(k=1 to n) Q(n)
= Q (n^2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the best case partition of quick sort? In words first, then derive it from T(n).

A

Each subproblem size <= n/2.

T(n) <= 2T(n/2) + PartitionTime(n)
= Q(nlgn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What types of lists is quicksort least efficient on? Give 2 fixes to this problem

A
  • Quicksort is not very efficient on small lists.
  • This is a problem because Quicksort will be called on lots of small lists.

• Fix 1: Use Insertion Sort on small problems.
• Fix 2: Leave small problems unsorted. Fix with one final Insertion Sort at end.
Why? Insertion Sort is very fast on almost-sorted lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the average case of quick sort if we get poorly balanced partitions like
T(n) <= T(9n/10) + T(n/10) + Q(n)?
Give the intuition for this.

A

Still get Q(n lg n)!! (As long as the split is of constant proportionality.)

Intuition: Can divide n by c > 1 only Q(lg n) times before getting 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Quick sort Partition produces a mix of “good” and “bad” splits, distributed randomly in the recursion tree.
• What is the running time likely to be in such a case?

A

When splits alternate between good and bad, the cost of bad split can be absorbed into the cost of good split.
Thus the running time is O(n lg n), though with larger hidden constants.

Bad then Good split:
Q(n) + Q(n-1) = Q(n)

Good split from start:
Q(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name 2 methods two randomize quicksort (Want to make running time independent of input ordering)

A
  1. Make the algorithm randomized.

2. Make every possible input equally likely.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain how we can make every possible input equally likely in quicksort.

A

For quicksort, it is sufficient if we can ensure that every

element is equally likely to be the pivot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Give 2 fixes to the quicksort problem: Input distribution may not be uniformly random.

A

• Fix 1: Use “randomly” selected pivot.
• Fix 2: Median-of-three Quicksort
– Use median of three fixed elements (say, the first,
middle, and last) as the pivot.
– To get O(n^2) behavior, we must continually be unlucky to see that two out of the three elements examined are among the largest or smallest of their sets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
let X = # comparisons over all calls to Partition.
Analyze the average case of Randomized quicksort.
A

Slide 24-25 lecture 22

O(nlgn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Prove this claim:

zi and zj are compared iff the first element to be chosen as a pivot from Zij is either zi or zj.

A

The only comparison made are made with the pivot in the partition code.
Use contradiction: if it isn’t the pivot, you can’t compare them in the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Does probabilistic analysis give average running time or worst-case running time?

A

average running time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly