Sorting Algorithms — Algorithms Practice Worksheet
Sorting arranges elements in order (ascending or descending). Different algorithms trade off simplicity, speed, and memory. Stability means equal elements keep their relative order after sorting.
Bubble sort repeatedly swaps adjacent out-of-order pairs — O(n²) time, simple but slow. Selection sort finds minimum and swaps — also O(n²). Merge sort divides, sorts halves, merges — O(n log n), stable, uses extra memory.
Quicksort picks a pivot, partitions smaller/larger — average O(n log n), in-place variants common. For small or nearly sorted data, simpler algorithms may suffice; for large data, O(n log n) is preferred.
Skills practiced
- Tracing simple sorts on small arrays
- Comparing time complexities
- Understanding stable vs. unstable sorts
- Choosing appropriate sorting algorithm
Practice Worksheet: Sorting Algorithms
Instructions: Solve each problem carefully. Show all work clearly. Write your final answer in the space provided or on a separate sheet as directed.
-
1.**Multiple Choice:** Which of the following sorting algorithms has the best average-case time complexity?
- A. Bubble Sort
- B. Insertion Sort
- C. Merge Sort
- D. Selection Sort
-
2.**Short Answer:** What is the worst-case time complexity of Quick Sort, and what condition causes it?
-
3.**Free Response:** Trace the execution of Merge Sort on the following array: . Show each recursive split and the merge steps.
-
4.**Multiple Choice:** Which sorting algorithm works by repeatedly swapping adjacent elements if they are in the wrong order?
- A. Merge Sort
- B. Bubble Sort
- C. Quick Sort
- D. Heap Sort
-
5.**Short Answer:** Explain why Insertion Sort is efficient for nearly sorted data. What is its best-case time complexity?
-
6.**Free Response:** Perform one complete pass of Bubble Sort on the array , showing the array after each swap. Then state whether the array is fully sorted after that pass.
-
7.**Multiple Choice:** Which of the following is **not** an in-place sorting algorithm?
- A. Quick Sort
- B. Heap Sort
- C. Merge Sort
- D. Insertion Sort
-
8.**Short Answer:** What is the key property of a heap that makes Heap Sort possible? Briefly describe how Heap Sort works.
-
9.**Free Response:** Given the array , show the result after each pass of Selection Sort. How many passes are needed to fully sort the array?
-
10.**Multiple Choice:** Which sorting algorithm has a worst-case time complexity of but an average-case of ?
- A. Merge Sort
- B. Quick Sort
- C. Heap Sort
- D. Bubble Sort
Answer Key
-
1.
Merge Sort has average-case ; Bubble, Insertion, and Selection are .Final answer: C
-
2.
Final answer: Worst-case time complexity is . This occurs when the pivot chosen is always the smallest or largest element (e.g., already sorted or reverse-sorted array with poor pivot selection).
-
3.
Final answer: Split: and ; Further splits until single elements: ; , , , ; Merge ; ; ; Merge and ; Merge and ; Final merge: and
-
4.
Bubble Sort repeatedly swaps adjacent elements if they are out of order.Final answer: B
-
5.
Final answer: Insertion Sort is efficient for nearly sorted data because it only makes a few comparisons and shifts; best-case time complexity is (already sorted).
-
6.
Final answer: Pass 1: ; Compare 5 and 1: swap ; Compare 5 and 4: swap ; Compare 5 and 2: swap ; Compare 5 and 8: no swap ; Array after pass: . Not fully sorted (4 and 2 are out of order).
-
7.
Merge Sort requires extra space, so it is not in-place.Final answer: C
-
8.
Final answer: A heap is a complete binary tree where each parent is greater (max-heap) or smaller (min-heap) than its children. Heap Sort builds a max-heap, then repeatedly swaps the root with the last element and reheapifies the reduced heap.
-
9.
Final answer: Pass 1: ; Pass 2: ; Pass 3: ; Pass 4: ; Pass 5: (no change) ; 6 passes are needed (for , Selection Sort requires passes).
-
10.
Quick Sort has worst-case but average-case .Final answer: B
Common mistakes to avoid
- Assuming bubble sort is O(n) with early exit always
- Confusing merge sort space complexity
- Incorrect pivot partition in quicksort traces
- Thinking all O(n²) sorts behave identically in practice
Generate your own like this
Want a fresh set of sorting algorithms problems at your chosen difficulty? Use WorksheetSmith to compile a custom, print-ready PDF in seconds.
Last updated: 2026