What property does a stable sorting algorithm guarantee?
09 Sorting Algorithms Online Quiz Questions
Use this free practice quiz with 20 questions to review 09 Sorting Algorithms, test your knowledge, and prepare for your next test or exam.
True or false: Standard selection sort performs Θ(n2) comparisons in its best, average, and worst cases.
- A
True
- B
False
Using selection sort that executes one swap operation at the end of each of the first n−1 passes, how many swap operations are executed for an array of five elements?
Insertion sort builds a one element at a time.
A small array is already nearly sorted, and the goal is to use a simple algorithm that can take advantage of that order. Which algorithm is the most appropriate choice?
- A
Selection sort
- B
Merge sort
- C
Insertion sort
- D
Heap sort
Select all algorithms that are described as stable in their standard forms in the material.
- A
Insertion sort
- B
Bubble sort
- C
Selection sort
- D
Merge sort
True or false: Quicksort can take O(n2) time when pivot choices repeatedly produce highly unbalanced partitions.
- A
True
- B
False
For heap sort in ascending order, which type of heap is built?
For ascending heap sort, the algorithm builds a .
Merge sort produces the sorted halves [3,7,8] and [2,4,9]. What is the result of merging these halves?
- A
[3, 2, 4, 7, 8, 9]
- B
[2, 4, 3, 7, 8, 9]
- C
[2, 3, 4, 7, 8, 9]
- D
[2, 3, 7, 4, 8, 9]
Select all algorithms in this list that can preserve the relative order of equal-key records under the standard conditions described in the material.
- A
Insertion sort
- B
Bubble sort
- C
Quicksort
- D
Merge sort
True or false: For arbitrary inputs, no comparison-based sorting algorithm can guarantee a worst-case running time in o(nlogn).
- A
True
- B
False
Explain what stability means in sorting and why it is useful when records are sorted by multiple fields. Use the equal-score example involving Ana and Cara to support your explanation.
A system requires a sorting algorithm with guaranteed worst-case O(nlogn) time and O(1) extra space. Which algorithm best matches these requirements?
- A
Merge sort
- B
Heap sort
- C
Quicksort
- D
Insertion sort
Which sequence is a correct ascending sort of the input [4, 1, 3, 2]?
- A
[1, 2, 3, 4]
- B
[1, 2, 4, 4]
- C
[1, 3, 2, 4]
- D
[4, 3, 2, 1]
Bubble sort compares adjacent elements and swaps them when they are out of order. What is the array after the first complete left-to-right pass on [5, 1, 4, 2]?
- A
[1, 4, 2, 5]
- B
[1, 2, 4, 5]
- C
[5, 1, 4, 2]
- D
[4, 1, 2, 5]
In a zero-based array representation of a binary heap, what is the parent index of the node at index 5?
Which sorting algorithm is generally a good choice for a small collection that is already nearly sorted?
A collection is first sorted by last name and then stably sorted by department. Which property ensures that records in the same department remain in their previous last-name order?
- A
In-place operation
- B
Stability
- C
Worst-case linear time
- D
Constant-time merging
Merge sort satisfies the recurrence T(n)=2T(2n)+Θ(n). What is its asymptotic running time?
- A
O(n)
- B
O(n2)
- C
O(nlogn)
- D
O(logn)