Sorting Algorithms — 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.
練習するスキル
- Tracing simple sorts on small arrays
- Comparing time complexities
- Understanding stable vs. unstable sorts
- Choosing appropriate sorting algorithm
練習ワークシート:Sorting Algorithms
指示: 各問題を丁寧に解きましょう。途中式もはっきりと書きましょう。最終的な答えは、指定された場所または指示に従って別の用紙に書いてください。
-
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 — 練習ワークシート(続き)
-
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 — 練習ワークシート(続き)
-
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 — 練習ワークシート(続き)
-
5.**Short Answer:** Explain why Insertion Sort is efficient for nearly sorted data. What is its best-case time complexity?
Sorting Algorithms — 練習ワークシート(続き)
-
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 — 練習ワークシート(続き)
-
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 — 練習ワークシート(続き)
-
8.**Short Answer:** What is the key property of a heap that makes Heap Sort possible? Briefly describe how Heap Sort works.
Sorting Algorithms — 練習ワークシート(続き)
-
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 — 練習ワークシート(続き)
-
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
解答集
-
1.
Merge Sort has average-case ; Bubble, Insertion, and Selection are .最終回答: C
-
2.
最終回答: 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.
最終回答: 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.最終回答: B
解答集(続き)
-
5.
最終回答: 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.
最終回答: 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.最終回答: C
-
8.
最終回答: 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.
最終回答: 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 .最終回答: B
避けるべきよくある間違い
- 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
自分だけのワークシートを作成
好きな難易度でsorting algorithmsの問題を新しく作成したいですか?WorksheetSmithを使えば、印刷可能なカスタムPDFを数秒で作成できます。
最終更新:2026