FirstHack 2026 — a 36-hour online hackathon built for first-year students.•₹1,00,000 prize pool•22 Oct – 4 Nov•Open to every branch and every stream•Certificate for every team that submits•3 rounds•FirstHack 2026 — a 36-hour online hackathon built for first-year students.•₹1,00,000 prize pool•22 Oct – 4 Nov•Open to every branch and every stream•Certificate for every team that submits•3 rounds•
Divide and conquer, the recurrences solved properly, and why quick sort is the default.
13 min read·Lesson 4 of 6·Pro
The idea both share
Sorting n elements costs about n^2. Sorting two halves costs 2 x (n/2)^2 = n^2/2 - half the work. Split again and it halves again. That is divide and conquer: break the problem, solve the pieces, combine.
Merge sort and quick sort differ in where the work happens. Merge sort splits carelessly and combines carefully. Quick sort splits carefully and combines for free.
Merge sort
C++
#include <iostream>
using namespace std;
void merge(int a[], int left, int mid, int right, int temp[]) {
int i = left, j = mid + 1, k = left;
The rest of this lesson is Pro
The free lessons of Algorithms and Complexity finish what
they start — read those first if you have not. This one goes further, and it
is part of the paid half.
A pass opens the paid lessons of every course, the mock test papers
and the company-wise series. It ends on its own date; nothing renews by itself.