Algorithms and Data Structures

Lesson 07 · 16 min

Sorting: merge sort, quick sort and the built-in sort

How the two main algorithms work and what arr.sort() costs in JavaScript.

16 minLesson 7 of 8Practice includedAsk AI on any point

Sorting is rarely written by hand in production code: there is arr.sort(). But interviewers love it, and its ideas ("split in half", "partition around a pivot") show up in many other problems. A comparison sort cannot beat O(n log n) in the general case, and both algorithms below reach that bound.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.