Designing a Solution
Real algorithm design draws on every unit concept at once: choose a strategy, back it with data structures, argue correctness, and analyze complexity.
A practical design workflow:
| Step | Action | Key Question |
|---|---|---|
| 1 | Understand | What are the exact inputs, outputs, and edge cases? |
| 2 | Strategy | Divide-and-conquer, dynamic programming, greedy, or graph traversal? |
| 3 | Structures | Which structures make hot operations fast (heap, hash table)? |
| 4 | Verify | Correctness proof and complexity analysis vs constraints. |
Common pitfall: reaching for an exotic technique when a simple approach works, or brute-forcing a problem whose size demands a better strategy.
Integrated Practice
These techniques are not separate exam topics but an integrated design toolkit. A strong algorithmist moves fluidly among them to balance correctness and efficiency.
Worked Example: Find the most frequent words in a huge text.
- Count: Use a hash table in time.
- Select: Use a heap of size in time over distinct words.
Rather than fully sorting, this design consciously combines a strategy (selection via heap) with the right structures, justified by its complexity.