Fundamentals 7 min read

Classic Algorithms: Divide‑Conquer, DP, Greedy, Backtracking, Branch‑and‑Bound

This article revisits fundamental algorithmic strategies—divide‑and‑conquer, dynamic programming, greedy methods, backtracking, and branch‑and‑bound—detailing their core ideas, applicable problem characteristics, key considerations, procedural steps, and illustrative examples such as merge sort, coin change, Huffman coding, and shortest‑path problems.

ITFLY8 Architecture Home
ITFLY8 Architecture Home
ITFLY8 Architecture Home
Classic Algorithms: Divide‑Conquer, DP, Greedy, Backtracking, Branch‑and‑Bound

Today I randomly found my old university textbook "Algorithm Design and Analysis" and decided to review several classic algorithms, summarizing their key concepts.

Divide‑and‑Conquer

Basic idea : Break a problem into independent smaller subproblems, solve each recursively, and combine their solutions.

Applicable problem features :

The problem becomes easy to solve once its size is reduced sufficiently.

The problem exhibits optimal substructure.

The subproblems are independent (no overlapping subproblems).

Key points :

How to decompose the problem into smaller instances with the same solution method.

The granularity of decomposition.

Steps : Decompose → Recursively solve → Merge.

divide-and-conquer(P) {
    if (|P| <= n0) adhoc(P); // solve small case
    divide P into smaller subinstances P1,P2,...,Pk; // split
    for (i = 1; i <= k; i++) {
        yi = divide-and-conquer(Pi); // solve subproblems
    }
    return merge(y1,...,yk); // combine results
}

Google’s core MapReduce algorithm is a derivative of divide‑and‑conquer.

Example: Merge Sort (illustrated below).

Merge sort illustration
Merge sort illustration

Dynamic Programming

Basic idea : Decompose the problem into overlapping subproblems, store solutions to subproblems, and reuse them to avoid redundant computation.

Applicable problem features :

Optimal substructure.

Repeated subproblems in recursive computation.

Steps :

Identify the property of optimal solutions and characterize the substructure.

Define the optimal value recursively.

Compute the optimal values bottom‑up.

Construct the optimal solution from the computed information.

Greedy Algorithms

Basic idea : Make the locally optimal choice at each step, hoping to reach a globally optimal solution.

Applicable problem features :

Greedy‑choice property: a global optimum can be built from a sequence of local optima.

Optimal substructure.

Steps : Repeatedly select the best local option.

Examples: coin change, Huffman coding, single‑source shortest path, minimum spanning tree (Prim and Kruskal).

Minimum spanning tree illustration
Minimum spanning tree illustration

Backtracking

Basic idea : Perform depth‑first search of the solution space tree, pruning branches that cannot lead to a solution.

Applicable problem features : The solution space can be represented as a tree that is easy to explore.

Steps :

Define the solution space.

Identify a searchable structure.

Search depth‑first, using a pruning function to discard invalid branches.

Example: N‑Queens problem.

N‑Queens illustration
N‑Queens illustration

Branch‑and‑Bound

Basic idea : Explore the solution space using breadth‑first or best‑first (minimum cost) strategies, expanding each active node once and discarding branches that cannot improve the current best solution.

Example: Single‑source shortest path problem in a directed graph with non‑negative edge weights.

Shortest path illustration
Shortest path illustration
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

dynamic programmingBacktrackingAlgorithmsdivide and conquerbranch-and-boundgreedy
ITFLY8 Architecture Home
Written by

ITFLY8 Architecture Home

ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.