CS Thinking / supporting

Merge Sort

Also known as: mergesort

principle

A divide-and-conquer sorting algorithm that splits a list in half, sorts each half recursively, then merges the sorted halves. One of the most efficient general-purpose sorting algorithms; used in many language standard libraries.

๐Ÿ’ก Intuition

Split a messy deck of cards in half, sort each half, then interleave them back in order.

Core Idea

Merge sort guarantees O(n log n) performance regardless of input order.

๐Ÿ”ฌ Example

[5,3,1,4] โ†’ split to [5,3] and [1,4] โ†’ sort to [3,5] and [1,4] โ†’ merge to [1,3,4,5].

๐ŸŽฏ Why It Matters

One of the most efficient general-purpose sorting algorithms; used in many language standard libraries.

โš ๏ธ Common Confusion

Merge sort uses extra memory proportional to the input size (unlike in-place sorts).

Related Concepts

How Merge Sort Connects to Other Ideas

To understand merge sort, you should first be comfortable with sorting, recursion and efficiency. Once you have a solid grasp of merge sort, you can move on to bubble sort and binary search.

Go Deeper

Frequently Asked Questions

What is Merge Sort in CS Thinking?

A divide-and-conquer sorting algorithm that splits a list in half, sorts each half recursively, then merges the sorted halves.

Why is Merge Sort important?

One of the most efficient general-purpose sorting algorithms; used in many language standard libraries.

What do students usually get wrong about Merge Sort?

Merge sort uses extra memory proportional to the input size (unlike in-place sorts).

What should I learn before Merge Sort?

Before studying Merge Sort, you should understand: sorting, recursion, efficiency.