Skip to content

Merge Sort Split and Merge
Step by Step

Every array splits in half until one number is left, then sorted pieces merge by taking the smaller front.

Step through every split and merge in both directions, then share a link to the step where the order went wrong.

What You Watch While Pieces Merge

Splits, comparisons and merges all show up on screen.

Merge sort does its real work while merging, when two sorted pieces become one.

CodeStory's visualiser shows every split, comparison and merge, pass by pass. Highlighted code lines follow along, and you can step back, step forward or play.

Try your own array with duplicates, then watch how the two pieces merge.

How Merge Sort Splits and Merges

Steps below follow the pieces on your screen.

  1. 1Split the array in half.
  2. 2Keep splitting every piece until only one number is left.
  3. 3Compare the front numbers of two sorted pieces.
  4. 4Move the smaller front number into the merged piece.
  5. 5Keep merging until one sorted array remains.

Merge Sort Cost in Time and Space

Interviewers ask why merge sort needs extra memory, and the visualiser counts real operations.

Time
O(n log n)counted from the comparisons and merges you step through
Space
O(n)extra memory to hold merged pieces
Pattern
SortingOrder grows one comparison at a time.

Everything in the App in One Place

Practice, interviews and tools all start free. Swipe to see the rest.

Sign up for 100 AI credits now and get 100 more every month. Start free in the app

Merge Sort Visualiser FAQs

Open the visualiser and follow the pieces as they merge.

Open the visualiser
What does the merge sort visualiser show?

CodeStory's visualiser shows every split, comparison and merge on an array you choose, with the highlighted line of code beside it. Use the controls to go back, go forward or let it play.

What is the time complexity of merge sort?

O(n log n) time and O(n) space in every case. CodeStory's visualiser counts real operations while it plays, so the number grows where you can see it.

How does merge sort work?

Merge sort splits the array in half until single numbers remain, then merges sorted pieces by taking the smaller front number every time.

Why is merge sort faster than bubble sort?

Merge sort takes O(n log n) time while bubble sort takes O(n²). Open both visualisers on the same array to compare the number of comparisons.

Can I use my own input?

Yes. Enter your own array and the visualiser splits and merges it step by step.

Is the visualiser free?

Yes. Sign up for 100 AI credits, collect 100 more every month and watch any algorithm with no credits spent.

Stuck on Sorting? Get a Free Callback

Tell CodeStory which sorting step loses you, and a mentor plans what comes next.

  1. 1CodeStory checks your level, from sorting basics to interview ready.
  2. 2CodeStory explains online and campus batches, with timings that fit your routine.
  3. 3You decide. No pressure, no payment on the call.

Get a free callback

I am a
I want to learn

Your number is only used for a CodeStory callback.