What enters the problem?
Size, shape, constraints?
Algorithm choice depends on input scale and structure.
Side 36
A study of how problems become representations and procedures. The same task can become easy or expensive depending on how information is organized and which operations the algorithm must perform.
Before choosing an algorithm, define what must be stored, queried, updated and traversed.
Size, shape, constraints?
Algorithm choice depends on input scale and structure.
Lookup, insert, rank, traverse?
The dominant operation should influence the data structure.
Array, map, tree, graph?
Representation determines which operations become cheap or expensive.
Iterate, recurse, divide?
An algorithm is a finite rule for transforming input into output.
Time and space.
Correctness is necessary; scalability decides whether the method remains useful.
No structure is universally best; each makes some operations fast by accepting costs elsewhere.
Fast random access; insertion in the middle can require shifting elements.
Flexible insertion and deletion; poor random access and locality.
Very fast average lookup when hashing and load are well controlled.
Useful for ordered search, indexes, parsing and nested relationships.
Efficient access to the smallest or largest item without fully sorting all items.
Represents networks, dependencies, routes and state transitions.
Learning patterns is more transferable than memorizing isolated procedures.
Works when large problems can be decomposed into smaller independent subproblems.
Works only when local choices can be proven to compose into a global optimum.
Store intermediate results so repeated computation becomes lookup.
Useful for combinatorial search when partial choices can be rejected early.
Elegant when the data or problem is naturally hierarchical.
Breadth-first and depth-first search expose different reach and memory behaviors.
Simple tasks reveal how representation, guarantees and input structure affect performance.
| Method | Core idea | Typical time | Useful when |
|---|---|---|---|
| Linear search | Check sequentially | O(n) | Data are small or unsorted |
| Binary search | Halve search interval | O(log n) | Data are ordered and indexable |
| Merge sort | Split and merge sorted halves | O(n log n) | Stable predictable sorting is useful |
| Quicksort | Partition around pivot | O(n log n) average | Fast in-memory sorting with good implementation |
| Heap sort | Repeated priority extraction | O(n log n) | Strong worst-case bound with low extra space |
Asymptotic analysis asks how resource use changes as input grows.
Cost stays bounded independent of input size.
Typical of balanced trees and binary search.
Often unavoidable when all input must be inspected.
Appears when logarithmic levels each process n work.
Can become prohibitive quickly as inputs scale.
Choose the representation before reaching for code.
Think hash table for counts plus a small heap for top-k maintenance rather than repeatedly sorting the entire dataset.
Represent intersections as nodes and roads as weighted edges; use graph algorithms rather than forcing the problem into a flat table.
A hash set is usually a stronger default than scanning an array repeatedly, assuming exact membership and memory trade-offs are acceptable.
Use a priority queue / heap rather than keeping the entire collection fully sorted after each update.