Computer Science I / Divide-and-Conquer Reasoning
Practice question · Put in order

Order how merge sort applies divide-and-conquer to a list.

Hints
  1. Divide before you conquer, and conquer before you combine.
  2. Merging is the combine step and comes last.
Show the answer
  1. Split the list into two halves
  2. Recursively sort the left half
  3. Recursively sort the right half
  4. Merge the two sorted halves into one
Why

Split, sort each half, then merge. The merge is cheap (linear), which is exactly the condition that makes divide-and-conquer pay off here.

Read the lesson: Divide-and-Conquer Reasoning →

Practise Divide-and-Conquer Reasoning

The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Divide-and-Conquer Reasoning