Divide and conquer

In Chapter 13, Sorting and Searching Algorithms, we learned how to develop the merge and quick sort algorithms. What both sorting solutions have in common is that they are divide and conquer algorithms. Divide and conquer is one of the approaches to algorithm design. It breaks the problem into small subproblems that are similar to the original problem, it solves the subproblems recursively, and combines the solutions of the subproblems to solve the original problem.

The divide and conquer algorithm can be split into three parts:

  1. Divide the original problem into smaller subproblems (smaller instances of the original problem).
  2. Conquer the smaller subproblems by solving them with recursive algorithms that return the solution ...

Get Learning JavaScript Data Structures and Algorithms - Third Edition 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.