🌍 Data Structures & Algorithms · subject
Data Structures & Algorithms Foundations & Complexity Analysis Syllabus
The Foundations & Complexity Analysis syllabus for Data Structures & Algorithms in full: 4 chapters and 16 topics, every one listed below, plus 52 Foundations & Complexity Analysis flashcards with answers.
Foundations & Complexity Analysis syllabus: all 4 chapters
Expand any chapter to see its topics and sub-topics.
-
Algorithm Analysis Fundamentals
4 topics- Asymptotic Notation
- Time Complexity
- Space Complexity
- Amortized Analysis
-
Mathematical Preliminaries
4 topics- Discrete Math Basics
- Modular Arithmetic
- Number Theory Essentials
- Probability for Algorithms
-
Recursion & Mathematical Induction
4 topics- Recursion Fundamentals
- Recurrence Relations
- Solving Recurrences
- Tail Recursion and Optimization
-
Bit Manipulation
4 topics- Bitwise Operators
- Bit Masking Techniques
- Common Bit Tricks
- Counting Set Bits
Data Structures & Algorithms Foundations & Complexity Analysis flashcards — 52 questions with answers
What does Big-O notation $O(g(n))$ formally represent?
An asymptotic upper bound. $f(n) = O(g(n))$ means there exist constants $c > 0$ and $n_0 > 0$ such that $0 \leq f(n) \leq c \cdot g(n)$ for all $n \geq n_0$.
Define Big-Omega notation $\Omega(g(n))$.
An asymptotic lower bound. $f(n) = \Omega(g(n))$ means there exist constants $c > 0$ and $n_0$ such that $0 \leq c \cdot g(n) \leq f(n)$ for all $n \geq n_0$.
Define Big-Theta notation $\Theta(g(n))$.
A tight asymptotic bound. $f(n) = \Theta(g(n))$ iff $f(n) = O(g(n))$ and $f(n) = \Omega(g(n))$, i.e. $c_1 g(n) \leq f(n) \leq c_2 g(n)$ for large $n$.
How do little-o $o(g(n))$ and little-omega $\omega(g(n))$ differ from Big-O and Big-Omega?
They denote strict (non-tight) bounds. $f = o(g)$ means $\lim_{n\to\infty} \frac{f(n)}{g(n)} = 0$; $f = \omega(g)$ means $\lim_{n\to\infty} \frac{f(n)}{g(n)} = \infty$.
Order these common complexity classes from fastest-growing to slowest-growing: $n!$, $2^{n}$, $n^{2}$, $n\log n$, $\log n$, $n$, $1$.
$n! > 2^{n} > n^{2} > n\log n > n > \log n > 1$.
In asymptotic analysis, why can constant factors and lower-order terms be dropped from $3n^{2} + 5n + 7$?
For large $n$ they are dominated by the leading term, so the growth rate is $\Theta(n^{2})$. Asymptotic notation describes behavior as $n \to \infty$.
What is the difference between worst-case, average-case, and best-case time complexity?
Worst-case = maximum running time over all inputs of size $n$; average-case = expected time over a distribution of inputs; best-case = minimum running time. Big-O usually refers to the worst case.
What time complexity does a simple binary search on a sorted array have, and why?
$O(\log n)$, because each comparison halves the remaining search space: $n \to \frac{n}{2} \to \frac{n}{4} \to \cdots \to 1$ takes $\log_2 n$ steps.
Define space complexity and distinguish auxiliary space from total space.
Space complexity is the total memory an algorithm uses as a function of input size. Auxiliary space excludes the input itself and counts only the extra working memory allocated.
What is the space complexity of a recursive algorithm, ignoring heap allocations?
It is $O(d)$ where $d$ is the maximum recursion depth, because each active call frame occupies stack space until it returns.
What is amortized analysis?
A technique that averages the cost of a sequence of operations over the whole sequence, so that occasional expensive operations are spread out, giving a realistic per-operation cost even when individual operations vary.
Name the three standard methods of amortized analysis.
The aggregate method, the accounting (banker's) method, and the potential method.
Why is appending to a dynamic array (doubling on resize) $O(1)$ amortized despite occasional $O(n)$ resizes?
Doubling means resizes cost $1 + 2 + 4 + \cdots + n \approx 2n$ total across $n$ inserts, so the average per insertion is $\frac{2n}{n} = O(1)$ amortized.
In the potential method, how is the amortized cost $\hat{c_i}$ of an operation defined?
$\hat{c_i} = c_i + \Phi(D_i) - \Phi(D_{i-1})$, where $c_i$ is the actual cost and $\Phi$ is the potential function of the data structure before and after.
State De Morgan's laws for logic.
$\lnot(p \land q) \equiv \lnot p \lor \lnot q$ and $\lnot(p \lor q) \equiv \lnot p \land \lnot q$.
What is the sum of the first $n$ positive integers?
$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$.
What is the formula for the number of subsets and the number of $k$-element subsets of an $n$-element set?
Total subsets: $2^{n}$. Subsets of size $k$: $\binom{n}{k} = \frac{n!}{k!(n-k)!}$.
State the Pigeonhole Principle.
If $n$ items are placed into $m$ containers with $n > m$, then at least one container holds at least $\lceil \frac{n}{m} \rceil \geq 2$ items.
State the Inclusion-Exclusion Principle for two sets.
$|A \cup B| = |A| + |B| - |A \cap B|$.
What is the closed form for a finite geometric series $\sum_{i=0}^{n-1} r^{i}$ with $r \neq 1$?
$\sum_{i=0}^{n-1} r^{i} = \frac{r^{n} - 1}{r - 1}$.
Show the other 32 Foundations & Complexity Analysis flashcards
Define the modulo operation and state the range of $a \bmod n$ for positive $n$.
$a \bmod n$ is the remainder of $a$ divided by $n$. For $n > 0$ it satisfies $0 \leq (a \bmod n) < n$.
State the distributive property of modular arithmetic for multiplication.
$(a \cdot b) \bmod n = \big((a \bmod n) \cdot (b \bmod n)\big) \bmod n$. The same distribution holds for addition and subtraction.
What does $a \equiv b \pmod{n}$ mean?
$a$ and $b$ are congruent modulo $n$, meaning $n$ divides $(a - b)$, equivalently they leave the same remainder when divided by $n$.
When does a modular multiplicative inverse of $a$ modulo $n$ exist, and what does it satisfy?
It exists iff $\gcd(a, n) = 1$. The inverse $a^{-1}$ satisfies $a \cdot a^{-1} \equiv 1 \pmod{n}$.
State Fermat's Little Theorem.
If $p$ is prime and $\gcd(a, p) = 1$, then $a^{p-1} \equiv 1 \pmod{p}$. Equivalently $a^{p} \equiv a \pmod{p}$ for all $a$.
What does the Euclidean algorithm compute, and what is its recurrence?
It computes $\gcd(a, b)$ via $\gcd(a, b) = \gcd(b, a \bmod b)$, terminating when the second argument is $0$. It runs in $O(\log \min(a,b))$ time.
State the relationship between GCD and LCM of two integers.
$\operatorname{lcm}(a, b) = \frac{|a \cdot b|}{\gcd(a, b)}$.
What is the time complexity of modular exponentiation via fast (binary) exponentiation?
$O(\log e)$ multiplications to compute $a^{e} \bmod n$, by repeatedly squaring and multiplying based on the bits of the exponent $e$.
State the Fundamental Theorem of Arithmetic.
Every integer greater than $1$ can be expressed uniquely as a product of prime powers, up to the ordering of factors: $n = p_1^{a_1} p_2^{a_2} \cdots p_k^{a_k}$.
How does the Sieve of Eratosthenes work and what is its time complexity?
It marks multiples of each prime starting from $2$ as composite; unmarked numbers are prime. Its time complexity is $O(n \log \log n)$.
Define the expected value of a discrete random variable $X$.
$E[X] = \sum_{x} x \cdot P(X = x)$, the probability-weighted average of all possible values.
State the linearity of expectation and note its key convenience.
$E[X + Y] = E[X] + E[Y]$ for any random variables $X, Y$. It holds even when $X$ and $Y$ are not independent, making it powerful for analyzing randomized algorithms.
What is the expected number of comparisons (order) for randomized quicksort, and why?
$O(n \log n)$ expected. A random pivot yields balanced splits on average; the expected comparison count is $\approx 2n \ln n$.
Define conditional probability $P(A \mid B)$.
$P(A \mid B) = \frac{P(A \cap B)}{P(B)}$, provided $P(B) > 0$.
State Bayes' Theorem.
$P(A \mid B) = \frac{P(B \mid A)\, P(A)}{P(B)}$.
What two components must every correct recursive function have?
A base case (that stops recursion without further calls) and a recursive case that makes progress toward the base case on a smaller subproblem.
Write the recurrence relation for the running time of the merge sort algorithm.
$T(n) = 2T\!\left(\frac{n}{2}\right) + \Theta(n)$, which solves to $T(n) = \Theta(n \log n)$.
State the Master Theorem for recurrences of the form $T(n) = aT\!\left(\frac{n}{b}\right) + f(n)$.
Compare $f(n)$ with $n^{\log_b a}$. Case 1: if $f(n) = O(n^{\log_b a - \epsilon})$ then $T(n) = \Theta(n^{\log_b a})$. Case 2: if $f(n) = \Theta(n^{\log_b a})$ then $T(n) = \Theta(n^{\log_b a} \log n)$. Case 3: if $f(n) = \Omega(n^{\log_b a + \epsilon})$ and regularity holds then $T(n) = \Theta(f(n))$.
Apply the Master Theorem to $T(n) = 2T\!\left(\frac{n}{2}\right) + \Theta(n)$.
Here $a = 2$, $b = 2$, so $n^{\log_b a} = n^{1} = n$, matching $f(n) = \Theta(n)$ (Case 2). Thus $T(n) = \Theta(n \log n)$.
Solve the recurrence $T(n) = T(n-1) + O(1)$ with $T(1) = O(1)$.
$T(n) = \Theta(n)$, since the constant work accumulates over $n$ levels of linear-depth recursion.
What is the substitution method for solving recurrences?
Guess a bound for the solution, then use mathematical induction to prove the guess is correct by verifying it satisfies the recurrence and base cases.
How does the recursion-tree method estimate a recurrence's cost?
Expand the recurrence into a tree where each node is a subproblem cost; sum the costs at each level, then sum across all levels to get the total, giving a good guess for a closed form.
Define the Fibonacci recurrence and give its exponential naive time complexity.
$F(n) = F(n-1) + F(n-2)$ with $F(0)=0, F(1)=1$. Naive recursion runs in $O(\varphi^{n})$ where $\varphi = \frac{1+\sqrt{5}}{2}$, i.e. exponential.
What is tail recursion?
A recursive call that is the very last operation in a function, with nothing left to compute after it returns. No pending work remains on the current frame.
Why can tail recursion be optimized, and what is the benefit?
Because no work follows the recursive call, the compiler can reuse the current stack frame (tail-call optimization), converting the recursion into a loop and reducing stack space from $O(n)$ to $O(1)$.
List the six common bitwise operators and their symbols.
AND ($\&$), OR ($|$), XOR ($\wedge$), NOT ($\sim$), left shift ($\ll$), and right shift ($\gg$).
What arithmetic effect do left shift and right shift have on an unsigned integer?
$x \ll k$ multiplies by $2^{k}$; $x \gg k$ performs integer division (floor) by $2^{k}$, i.e. $\lfloor \frac{x}{2^{k}} \rfloor$.
How do you check whether the $i$-th bit of $x$ is set, and how do you set it?
Check: $(x \;\&\; (1 \ll i)) \neq 0$. Set: $x \;|\; (1 \ll i)$. Clear: $x \;\&\; \sim(1 \ll i)$. Toggle: $x \wedge (1 \ll i)$.
What does the bit trick $x \;\&\; (x-1)$ do?
It clears (turns off) the lowest set bit of $x$. Repeatedly applying it counts set bits, and $x \;\&\; (x-1) = 0$ tests whether $x$ is a power of two.
How do you extract the lowest set bit of $x$, and how do you test if $x$ is a power of two?
Lowest set bit: $x \;\&\; (-x)$. Power-of-two test: $x > 0$ and $(x \;\&\; (x-1)) = 0$.
How is a subset of an $n$-element set represented with bit masking, and how many masks are there?
Each element maps to one bit; a subset is an integer where set bits indicate membership. There are $2^{n}$ possible masks, enumerated by iterating an integer from $0$ to $2^{n}-1$.
Using Brian Kernighan's algorithm, what is the time complexity of counting set bits in an integer, and why is it efficient?
It runs in $O(s)$ where $s$ is the number of set bits, because each iteration of $x = x \;\&\; (x-1)$ removes exactly one set bit, rather than looping over all bit positions.
Data Structures & Algorithms Foundations & Complexity Analysis FAQ
What is in the Data Structures & Algorithms Foundations & Complexity Analysis syllabus?
Data Structures & Algorithms Foundations & Complexity Analysis is split into 4 chapters: Algorithm Analysis Fundamentals, Mathematical Preliminaries, Recursion & Mathematical Induction and Bit Manipulation. Together they contain 16 topics.
How many chapters are in Data Structures & Algorithms Foundations & Complexity Analysis?
4 chapters, containing 16 topics. The largest chapter is Algorithm Analysis Fundamentals, with 4 topics.
Are there flashcards for Data Structures & Algorithms Foundations & Complexity Analysis?
Yes — a 52-card Foundations & Complexity Analysis deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.