Trace Insertion Sort
Correctness and Invariants
Time Complexity
Merge Sort
Algorithm Choice
100

What does insertion sort do with each new item?

It inserts each new item into the correct position in the sorted left part.

100

What does a correct algorithm do?

It gives the right answer for valid inputs.

100

What does time complexity describe?

How running time grows as input size grows.

100

What design strategy does merge sort use?

Divide and conquer.

100

For a large unsorted array, which is usually more suitable?

Merge sort.

200

In insertion sort, which part remains sorted after each step?

The processed left part.

200

What is an invariant?

Something that remains true as the algorithm runs.

200

What is insertion sort’s best-case time complexity?

O(n)

200

What are merge sort’s three main steps?

Divide, sort recursively, and merge.

200

When can insertion sort still be useful?

It is simple and works well for small or nearly sorted inputs.

300

In [12, 38, 45], where should 29 be inserted?

Between 12 and 38.

300

What is the key invariant in insertion sort?

After each step, the processed left part remains sorted.

300

What is the base case in merge sort?

O(n^2)

300

Why is a one-element array already sorted?

There is nothing out of order.

300

Why does merge sort scale better for large unsorted inputs?

Its O(n \log n) grows more slowly than O(n^2).

400

After inserting 29 into [12, 38, 45, 29, 7], what is the array?

[12, 29, 38, 45, 7]

400

How does the invariant support correctness?

It shows each step preserves sorted order.

400

Why does O(n^2) become costly for large inputs?

The number of comparisons and shifts grows very quickly.

400

Why does merge sort have about (\log n) levels?

Because the array is repeatedly divided in half.

400

What trade-off may favour insertion sort over merge sort?

Insertion sort uses less extra space.

500

Why can insertion sort work well on nearly sorted input?

Few elements need to move.

500

Why is the whole array sorted when insertion sort ends?

All elements have been processed into the sorted part.

500

Which grows more slowly for large (n): O(n^2) or O(n \log n)?

O(n \log n)

500

Why is merge sort O(n \log n)?

There are about (\log n) levels, and each level processes (n) elements.

500

What is the main lesson in algorithm choice?

Correctness matters, but efficiency and context also matter.