True or false: A stable sorting algorithm preserves the original relative order of records that have equal keys.
9 Sorting Algorithms Online Quiz Questions
Use this free practice quiz with 20 questions to review 9 Sorting Algorithms, test your knowledge, and prepare for your next test or exam.
In bubble sort, what is guaranteed after one complete pass through the current unsorted portion?
- A
The smallest unsorted element
- B
The largest unsorted element
- C
The middle unsorted element
- D
The first element examined
Which named sorting algorithm is characterized by approximately n swaps while still performing about n2 comparisons?
Insertion sort builds a one element at a time.
What is the best-case time complexity of the standard selection-sort implementation described in the material?
- A
O(n)
- B
O(nlogn)
- C
O(n2)
- D
O(logn)
True or false: Merge sort can be stable when its merge operation chooses the left element first whenever two next elements are equal.
- A
True
- B
False
Which algorithms below are described as stable under the implementations specified in the material? Select all that apply.
- A
Bubble sort
- B
Insertion sort
- C
Merge sort
- D
Selection sort
How many inversions are in the array [3,1,2]?
In quicksort, the chosen value used to divide the array into partitions is called the .
A small array is already nearly sorted and has few inversions. Which algorithm is the most suitable choice according to the material?
- A
Selection sort
- B
Insertion sort
- C
Merge sort
- D
Quicksort with an unrandomized first-element pivot
Which statements about quicksort are supported by the material? Select all that apply.
- A
Its average-case time can be O(nlogn) with suitable pivot selection.
- B
Its worst-case time is always O(nlogn).
- C
Repeatedly unbalanced partitions can cause O(n2) time.
- D
Its standard implementations preserve equal-key order.
What extra space is required by the usual array implementation of merge sort?
- A
O(1)
- B
O(logn)
- C
O(n)
- D
O(n2)
Recommend suitable algorithms for each of these situations and justify each recommendation: (1) a small, nearly sorted array; (2) records that must retain equal-key order with a guaranteed O(nlogn) time bound; and (3) a setting that prioritizes average-case speed and low extra array memory but can use pivot randomization.
Which algorithm is generally described as using O(1) extra array space for in-place partitioning, while still requiring recursion-stack space?
- A
Quicksort
- B
Merge sort
- C
Selection sort
- D
Bubble sort
What is the primary purpose of sorting a collection of items?
- A
Rearranging items into a specified order
- B
Encrypting every item in an array
- C
Removing all duplicate items
- D
Randomly changing the positions of items
Why might selection sort be chosen when writing to memory is especially expensive?
- A
It guarantees linear running time on every input.
- B
It minimizes the number of swaps compared with the other elementary quadratic sorts.
- C
It is stable in its standard implementation.
- D
It requires O(n) additional array space.
Which situation is the best fit for insertion sort?
- A
A large unsorted array where guaranteed O(nlogn) time is required
- B
A small array that is already nearly sorted
- C
An application that requires the fewest possible comparisons
- D
An application that requires stable sorting with O(n) auxiliary memory
True or false: The standard implementation of selection sort is stable.
- A
True
- B
False
Using the standard selection sort pseudocode, how many element comparisons are performed when sorting an array of 6 elements?
What is the algorithm term for a pair of elements that appears in the opposite order from the desired ordering?