Most algorithms are instances of a few design techniques. Brute force tries everything. Divide and conquer splits a problem into independent halves. Greedy algorithms take the locally best choice. Dynamic programming (with memoization or tabulation) reuses answers to overlapping subproblems. Two pointers and sliding windows turn nested loops over arrays into single passes. This section shows each technique with a worked C example and when it applies.
Start with brute force.
A correct slow solution is a baseline for testing. Then ask what repeated or unnecessary work you can remove.
Path
Learning Path
Work through the stages in order, or jump to a topic from the index below (8 tutorials).
Common mistakes when learning algorithm techniques in C.
misuse
Using greedy where it fails
Greedy is only correct when the problem has the greedy-choice property. Test it against brute force.
dp
Dynamic programming without overlap
If subproblems do not repeat, DP just adds memory.
sorted
Two pointers on unsorted data
Most two-pointer pair searches require sorted input.
Remember
Key Takeaways
Recognize the pattern first.
Verify against a simple baseline.
Choose a technique by problem structure.
One line: Most algorithms are instances of a few design techniques.
Frequently Asked Questions
Brute force, divide and conquer, greedy algorithms, dynamic programming, backtracking, and array techniques such as two pointers and sliding windows.
Look at the structure: independent subproblems suggest divide and conquer, overlapping subproblems suggest dynamic programming, and a safe locally best choice suggests greedy.
Memoization is top-down recursion with a cache; tabulation fills a table bottom-up with loops.