Sorting Algorithms — Fiche d'exercices de Algorithms
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.
Compétences travaillées
- Tracing simple sorts on small arrays
- Comparing time complexities
- Understanding stable vs. unstable sorts
- Choosing appropriate sorting algorithm
Fiche d'exercices : Sorting Algorithms
Consignes : Résous chaque problème avec soin. Montre clairement tout ton travail. Écris ta réponse finale dans l'espace prévu ou sur une feuille séparée comme indiqué.
-
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
Sorting Algorithms — Fiche d'exercices (suite)
-
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.
Sorting Algorithms — Fiche d'exercices (suite)
-
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
Sorting Algorithms — Fiche d'exercices (suite)
-
5.**Short Answer:** Explain why Insertion Sort is efficient for nearly sorted data. What is its best-case time complexity?
Sorting Algorithms — Fiche d'exercices (suite)
-
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.
Sorting Algorithms — Fiche d'exercices (suite)
-
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
Sorting Algorithms — Fiche d'exercices (suite)
-
8.**Short Answer:** What is the key property of a heap that makes Heap Sort possible? Briefly describe how Heap Sort works.
Sorting Algorithms — Fiche d'exercices (suite)
-
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?
Sorting Algorithms — Fiche d'exercices (suite)
-
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
Corrigé
-
1.
Merge Sort has average-case ; Bubble, Insertion, and Selection are .Réponse finale : C
-
2.
Réponse finale : 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.
Réponse finale : 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.Réponse finale : B
Corrigé (suite)
-
5.
Réponse finale : 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.
Réponse finale : 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.Réponse finale : C
-
8.
Réponse finale : 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.
Corrigé (suite)
-
9.
Réponse finale : 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 .Réponse finale : B
Erreurs fréquentes à éviter
- 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
Générez la vôtre
Vous voulez un nouvel ensemble de problèmes de sorting algorithms à la difficulté de votre choix ? Utilisez WorksheetSmith pour compiler un PDF personnalisé prêt à imprimer en quelques secondes.
Dernière mise à jour : 2026