Test #1 Flashcards
What should you know about optimally sorting 5 elements
- We can sort 5 items with 7 comparisons.
- 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.
- 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.
Any comparison-based algorithm for sorting a list of size n must perform at least _____ comparisons in the worst case.
Ω(n log n)
Any comparison-based algorithm for sorting a list of size n must perform at least ___ comparisons in the worst case.
Ceil(log(n!))
What is worst-case time for quick-sort?
O(n2)
What is worst-case time for insertion sort?
O(n2)
What is worst-case time for merge sort?
O(n log n)
What is worst-case time for heap sort?
O(n log n)
What is the storage requirement for Insertion sort?
In place
What is the storage requirement for quick sort?
O(log n) extra for stack
What is the storage requirement for heap sort?
In-place
What is Quick Sort expected time?
O(n log n)
When is insertion sort good?
Good when input is almost sorted
A priority queue need to minimally support the following operations…
Insert an item w a given key
Delete an item
Select the item with the most urgent priority in the priority queue
What is totla time of SiftUp helper function for binary heaps?
at most 1 comparison on each level, so total time is O(log n)
What is total time of SiftDown helper function for binary heaps?
At most 2 comparisons at each level, so the total time is O(log n)