Lecture 1 - Comparison Sorts Flashcards

1
Q

What comparison sorts have average+worst time complexity of O(n^2)?

A

Selection sort
Insertion sort
Bubble sort

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

What comparison sorts have average and worst time complexity of O(nlogn)?`

A

Merge sort
Heap sort

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

What is the fastest comparison - based sorting algorithm in practice?

A

Quicksort

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

What is the worst time complexity of quicksort?

A

O(n^2)

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

What is the average time complexity of quicksort?

A

O(nlogn)

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

What is the claim on comparison based sorting algorithms?

A

No comparison based sorting algorithm can have a better complexity than O(nlogn).

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

How to prove comparison based algorithms can’t do better than O(nlogn)?

A

Via a decision tree

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

What does the number of leafs of a decision tree represent?

A

Number of outcomes.
This can also be calculated via !n.

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

Why can the complexity not be better than the height of the decision tree?

A

Since we have to reach a leaf to get a result.

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

What is the maximum number of leaf nodes in a binary tree?

A

2^(h+1) - 1

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

Is a decision tree a binary tree?

A

Yes

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

What is the equation to prove the O(nlogn) claim?

A

!n <= 2^(h+1)-1 < 2^(h+1)

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

How to solve !n <= 2^(h+1)-1 < 2^(h+1).

A
  • take log2 of both sides
    h+1 > log2 (!n)
  • since !n > (n/2) ^ (n/2)
    h+1 > log2(n/2)^(n/2)
  • simplify
    h+1 > n/2 log2(n/2)
  • expand
    h+1 > n/2 log2n - n/2 log22
    h > n/2 log2n - n/2 - 1
    -> this gives O(nlogn) ignoring smaller terms
How well did you know this?
1
Not at all
2
3
4
5
Perfectly