Sorting Algorithms — Algorithms Übungsblatt
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.
Geübte Fähigkeiten
- Tracing simple sorts on small arrays
- Comparing time complexities
- Understanding stable vs. unstable sorts
- Choosing appropriate sorting algorithm
Übungsblatt: Sorting Algorithms
Anleitung: Löse jede Aufgabe sorgfältig. Zeige deine Arbeit klar. Schreibe deine endgültige Antwort in das vorgesehene Feld oder wie angewiesen auf ein separates Blatt.
-
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 — Übungsblatt (Fortsetzung)
-
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 — Übungsblatt (Fortsetzung)
-
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 — Übungsblatt (Fortsetzung)
-
5.**Short Answer:** Explain why Insertion Sort is efficient for nearly sorted data. What is its best-case time complexity?
Sorting Algorithms — Übungsblatt (Fortsetzung)
-
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 — Übungsblatt (Fortsetzung)
-
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 — Übungsblatt (Fortsetzung)
-
8.**Short Answer:** What is the key property of a heap that makes Heap Sort possible? Briefly describe how Heap Sort works.
Sorting Algorithms — Übungsblatt (Fortsetzung)
-
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 — Übungsblatt (Fortsetzung)
-
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
Lösungsschlüssel
-
1.
Merge Sort has average-case ; Bubble, Insertion, and Selection are .Endgültige Antwort: C
-
2.
Endgültige Antwort: 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.
Endgültige Antwort: 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.Endgültige Antwort: B
Lösungsschlüssel (Fortsetzung)
-
5.
Endgültige Antwort: 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.
Endgültige Antwort: 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.Endgültige Antwort: C
-
8.
Endgültige Antwort: 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.
Lösungsschlüssel (Fortsetzung)
-
9.
Endgültige Antwort: 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 .Endgültige Antwort: B
Häufige Fehler, die es zu vermeiden gilt
- 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
Erstelle dein eigenes Arbeitsblatt
Möchtest du neue sorting algorithms-Aufgaben in deiner gewünschten Schwierigkeit? Nutze WorksheetSmith, um in Sekunden ein individuelles, druckfertiges PDF zu erstellen.
Zuletzt aktualisiert: 2026