kids encyclopedia robot

Merge sort facts for kids

Kids Encyclopedia Facts

Merge sort is a clever way to sort a list of items, like numbers or words. It's a type of divide and conquer algorithm. This means it solves a big problem by breaking it into smaller, easier problems. John von Neumann first came up with this idea in 1945.

How Merge Sort Works

Merge sort uses a simple three-step process to get everything in order:

  • First, it takes a list of items and splits it into two smaller lists. Each new list is about half the size of the original.
  • Next, it applies the same sorting process to each of these two smaller lists. It keeps splitting them until it has many lists, each with only one item. A list with one item is already sorted!
  • Finally, it merges these sorted smaller lists back together. It combines two sorted lists into one larger, perfectly sorted list. This merging step is done carefully to keep everything in order.

Comparing Merge Sort to Quicksort

Another popular sorting method is quicksort, which was developed later in 1960. Both merge sort and quicksort use the "divide and conquer" idea, but they do it differently.

With merge sort, splitting the lists is very easy. You just cut the list in half. The tricky part is putting the sorted halves back together. You need to compare items from both halves to merge them correctly.

With quicksort, splitting the list is a bit more complicated. You have to pick a "pivot" item and arrange the other items around it. But once that's done, merging the lists back together is very simple.

Another important difference is that merge sort is a stable sorting algorithm. This means if you have two items that are exactly the same, their original order in the list will stay the same after sorting. Quicksort doesn't always do this.

Images for kids

See also

Kids robot.svg In Spanish: Ordenamiento por mezcla para niños

kids search engine
Merge sort Facts for Kids. Kiddle Encyclopedia.