Algorithm
This post is a concept guide to algorithms – covering exam questions, key takeaways, and reference points.
In a Nutshell
An algorithm is a finite, precisely defined sequence of steps that solves a problem. We evaluate algorithms by correctness, runtime, memory usage, stability, and robustness.
Concise Technical Overview
An algorithm processes well-defined inputs and produces deterministic or probabilistic outputs. It’s usually described in pseudocode with preconditions and postconditions.
Analysis relies on asymptotic notation:
- O (upper bound)
- Ω (lower bound)
- Θ (tight bound)
Often separated by best-case, average-case, and worst-case scenarios, plus amortized analysis.
Common design paradigms:
- Divide and Conquer
- Greedy
- Dynamic Programming
- Backtracking
- Randomization
Data structures (arrays, linked lists, heaps, hash tables, trees, graphs) heavily influence real-world performance.
Security angle: worst-case inputs can trigger algorithmic complexity attacks, so input validation and resource limits matter.
Key Exam Points
- Exact vs heuristic/approximate; deterministic vs randomized
- O/Ω/Θ; best/average/worst; amortized
- Paradigms: D&C, Greedy, DP, Backtracking
- IHK standards: preconditions/postconditions, termination, loop invariants
- Practice: choose the right data structure, measure before optimizing
- Security: harden against worst-case, set limits
- Documentation: problem definition, pseudocode, complexity, test reports
Core Components
- Specification (input/output/constraints)
- Cost model (time/space/I/O)
- Pseudocode (sequence, branching, loops)
- Data structure selection
- Correctness (invariants/induction/termination)
- Complexity analysis
- Design approach
- Implementation details (recursion/iteration)
- Robustness and security
- Testing (edge cases, fuzzing, regression)
Practical Example: Insertion Sort (Pseudocode)
function insertionSort(a)
for i from 1 to length(a)-1
key <- a[i]
j <- i-1
while j >= 0 and a[j] > key
a[j+1] <- a[j]
j <- j-1
end
a[j+1] <- key
end
return a
Explanation: Stable, in-place, worst-case O(n^2), best-case O(n) on nearly sorted data.
Typical Exam Questions (with Brief Answers)
- O vs Ω vs Θ? O is the upper bound, Ω is the lower bound, Θ is the tight bound.
- When is Greedy correct? When optimal substructure and the greedy-choice property both hold.
- How do you spot Dynamic Programming? Overlapping subproblems plus optimal substructure.
- How do you prove termination? Define a variant function that strictly decreases and is bounded below.
Free Response
For IHK exams: define the problem clearly, write clean pseudocode, justify the complexity, and test edge cases. In production systems, cache effects, I/O behavior, and hardening against worst-case inputs are critical.
Learning Strategy
- Write pseudocode and invariants for past exam problems.
- Measure runtimes (linear vs binary search, different sorts).
- Model a DP example (knapsack) as a table.
- Always test boundary conditions and exit criteria.



