Merge Sort VisualizerO(N log N) Stable & Guaranteed

LeetCode #148
Comparisons0
Array Writes0
Accesses0
Step 1 / 0
54
[0]
26
[1]
93
[2]
17
[3]
77
[4]
31
[5]
44
[6]
55
[7]
Code Execution

💡 Merge Sort in Layman's Terms

Merge Sort uses Divide and Conquer! It cuts the list down into tiny 1-element piles (which are automatically sorted), and then zips pairs of sorted piles back together into one master list.

How it Works Step-by-Step:
  • 1Split Down to Singles: Keep splitting the list in half until every single number sits in its own tiny 1-item pile.
  • 2Compare Front Cards: Look at the front number of two neighboring sorted piles. Pick whichever number is smaller.
  • 3Zip Back Together: Push the smaller number into your combined list, and repeat until both piles merge into one perfectly sorted deck!
🎴 Real-World Analogy: Zipping Two Pre-Sorted Decks of Cards

Imagine having two small piles of cards sitting face-up on a table. Pile A has [3, 7, 9] and Pile B has [2, 5, 8]. Both piles are already sorted internally! To combine them into one master sorted pile, you simply look at the front cards: compare 3 vs 2, take 2 first. Then compare 3 vs 5, take 3. Then compare 7 vs 5, take 5... You keep taking the smaller front card until both piles form one grand sorted deck!

State Variables
left0
mid0
right7
i0
j0
Time: O(N log N)Space: O(N)
LeetCode #148