25

Mergesort

One of the most popular sorting algorithms you’ll bump into is mergesort. It was designed in the 1940s when dinosaurs roamed the jungles (Figure 25-1).

Images

FIGURE 25-1

Dinosaurs doing dinosaur things. (Source: Winsor McCay, Gerdie the Dinosaur, animated short film, 1914. https://en.wikipedia.org/wiki/Gertie_the_Dinosaur#.)

Ever since then, mergesort (and variants of it!) can be seen everywhere—ranging from sort implementations in the Perl, Python, and Java languages to sorting data in tape drives. Okay, maybe the tape drives bit isn’t relevant today, but mergesort comes up in a lot of places due to its efficiency.

In this chapter, ...

Get Absolute Beginner's Guide to Algorithms: A Practical Introduction to Data Structures and Algorithms in JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.