IntermediateAbout 15 min

    Merge Sort

    Read the full article on Substack

    7 min read.

    A classic Divide and Conquer algorithm. It divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves.

    Think of it this way: Imagine sorting a deck of cards. It's hard to sort 52 cards at once. So you split the deck until you have piles of 1 card (which are sorted!). Then you merge pairs of piles back together in order. Divide and Conquer!

    3827433982100123456
    buffer0123456

    Start: split until each piece has one element, then merge sorted pieces.

    1/55

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    Divide, then conquer

    Sequence

    Order the stages of merge sort.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    5 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    Is Merge Sort a stable sorting algorithm?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going