Module 07 of 12

Sorting & Searching

Lessons

About This Module

Sorting puts data in order, and order is what makes fast searching possible. Once a list is sorted, binary search can find any value by repeatedly halving the range, so a search that takes O(n) on unsorted data takes only O(log n). Sorting is also a first step in many other problems, from finding duplicates to merging intervals.

This module starts with the simple sorts: bubble, selection and insertion sort. They are easy to follow and run in O(n²) time, which shows why better methods are needed. It then covers the two standard fast sorts, merge sort and quick sort, both built on divide and conquer and both typically O(n log n), so the recursion from the previous module is put to use.

The last lesson is about searching. Binary search looks simple, but small mistakes with the bounds and the midpoint are common, so it is worth working through carefully. Watch the lessons in order, then continue on to Trees, BSTs & Tries.

Lessons

4 videos
01

Bubble, Insertion & Selection Sort

The three fundamental simple sorts in a visual, intuitive way: how each one moves elements into place and why they are O(n²).

02

What Is Merge Sort? How Merge Sort Works Step-by-Step

Merge sort as a divide-and-conquer algorithm: split the data into smaller subarrays, sort each one, then merge them back together in order.

03

Quick Sort Algorithm Explained Visually

A step-by-step visual demonstration of quick sort: choosing a pivot, partitioning the array around it, and sorting each side recursively.

04

Binary Search Algorithm Explained (LeetCode 704)

Binary search on a sorted array: how the search range is halved each step, shown on the classic LeetCode 704 problem.