When simple sorters

Beginner Algorithms and Data Structures English
Also available: Deutsch
Created by Best · 16.08.2026 at 09:13 UTC

Simple algorithms are worthwhile for small n, for teaching purposes, and as a base case in hybrids (e.g. insertion in quicksort leaves).

For large n: $O(n \log n)$ algorithms.

Method Extra memory (classic) Stable
Selection in-place no
Insertion in-place yes
Merge extra array yes
Quicksort in-place partition no
## Where used

n very small, nearly sorted, or as a base case in hybrids. Elsewhere: Arrays.sort / List.sort.

Depth

Simple quadratic sorters are often competitive for small arrays because they have low overhead and work locally. Insertion Sort is also suitable for nearly sorted data and as a finishing step for small subarrays in hybrid methods.

Selection Sort offers a predictably small number of element movements. This can be relevant for media with expensive write operations. However, for large, unordered data, the many comparisons dominate, so asymptotically better algorithms typically win.

Difficulty levels

  1. Recognize input size and presorting as selection criteria.
  2. Distinguish comparison costs from write costs.
  3. Justify the use as a base case of a hybrid sorter.

Pitfalls

The statement "small input" has no universal limit. Data type, runtime environment, cache behavior, and comparison function influence the actual crossover point.

University approvals: 0
Tasks
Question 1

When is Insertion Sort practically appealing?

Question 2

Why do hybrid sorters often use insertion sort for small subarrays?

Question 3

Implement sortSmall using Insertion Sort.

Hint

You read and write array elements with a[index]. A local variable can hold a value during several shifts.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Algorithms and Data Structures
  • Difficulty: Beginner
  • Completed: 0 users
Creator
Best
Best
BestBuddy