Test #1 Flashcards

1
Q

What should you know about optimally sorting 5 elements

A
  1. We can sort 5 items with 7 comparisons.
  2. Merge sort requires 8 comparisons to sort 5 items. Since we can sort 5 items with 7 comparisons, this means that merge sort is not optimal if we count exact comparisons.
  3. The lower bound on comparison sorting for n = 5 is 7 comparisons. Since we can sort 5 items with 7 comparisons, this is the best possible lower bound for sorting 5 items.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Any comparison-based algorithm for sorting a list of size n must perform at least _____ comparisons in the worst case.

A

Ω(n log n)

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

Any comparison-based algorithm for sorting a list of size n must perform at least ___ comparisons in the worst case.

A

Ceil(log(n!))

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

What is worst-case time for quick-sort?

A

O(n2)

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

What is worst-case time for insertion sort?

A

O(n2)

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

What is worst-case time for merge sort?

A

O(n log n)

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

What is worst-case time for heap sort?

A

O(n log n)

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

What is the storage requirement for Insertion sort?

A

In place

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

What is the storage requirement for quick sort?

A

O(log n) extra for stack

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

What is the storage requirement for heap sort?

A

In-place

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

What is Quick Sort expected time?

A

O(n log n)

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

When is insertion sort good?

A

Good when input is almost sorted

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

A priority queue need to minimally support the following operations…

A

Insert an item w a given key

Delete an item

Select the item with the most urgent priority in the priority queue

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

What is totla time of SiftUp helper function for binary heaps?

A

at most 1 comparison on each level, so total time is O(log n)

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

What is total time of SiftDown helper function for binary heaps?

A

At most 2 comparisons at each level, so the total time is O(log n)

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

Total time of Binary Heap Insertion?

A

Sift time dominates, so total time is O(log n)

17
Q

Total time for Binary Heap Deletion?

A

Sift up/down time dominates, so total time is O(log n)

18
Q

Extract Max binary heap total time?

A

Delete time dominates, so total time is O(log n)

19
Q

What is the recurrence equatuion and asymptoic analysis for Merge Sort?

A
20
Q
A