Quiz 2 Flashcards
Is heapsort a stable sorting algorithm?
No, it is not stable.
Does heapsort sort in place?
Yes, it sorts in place.
Is insertion sort stable?
Yes, insertion sort is stable.
Is insertion sort in-place?
Yes, insertion sort operates in place.
Is merge sort stable?
Yes, merge sort is stable.
Is merge sort in-place?
No, merge sort requires extra space.
What is the lower bound for comparison-based sorting algorithms?
Ω(n log n)
What is the runtime of randomized quicksort in the average case?
O(nlogn)
Is quicksort stable?
No, quicksort is not a stable sorting algorithm.
Does quicksort sort in place?
Yes, quicksort operates in place.
Is selection sort stable?
No, selection sort is not stable.
Is selection sort in-place?
Yes, it sorts in place.
What is heapsort?
Heapsort is a comparison-based sorting algorithm that sorts an array in place by building a heap data structure and extracting elements in order.
How does heapsort work?
Heapsort works by first organizing the data into a binary heap. The largest element is placed at the root. Then it repeatedly extracts the root and places it at the end of the sorted array. With each extraction, the heap property is restored.
What is the worst case runtime complexity of heapsort?
O(nlogn)
What is the space complexity of heapsort?
O(1). Heapsort operates in place, requiring constant extra space.
When should heapsort be preferred over other sorting algorithms?
When fast in-place sorting is required. The O(nlogn) runtime is comparable to efficient algorithms like quicksort, but heapsort has the advantage of being in-place.
What is insertion sort?
Insertion sort iterates through the array, swapping the current element with others to insert it in the correct sorted position.
What is the best case runtime complexity of insertion sort?
O(n) when the array is already sorted.
What is the average and worst case runtime complexity of insertion sort?
O(n^2)
When is insertion sort preferred?
For small or mostly sorted data. The simplicity provides advantages in these cases.
What is merge sort?
Merge sort divides the array recursively into halves until single elements remain. It then merges the smaller sorted arrays to produce the final sorted array.
What is the runtime complexity of merge sort?
O(nlogn) for all cases.
What are the space requirements of merge sort?
O(n) auxiliary space is required. It is not an in-place sort.