Algorithms and Big-O for coding interviews – Server Side interview prep
261 interview-style multiple-choice questions on Algorithms and Big-O for coding interviews, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 55 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 18.1 Big-O and complexity analysis
- 18.2 Searching and binary search
- 18.3 Sorting algorithms
- 18.4 Recursion and divide and conquer
- 18.5 Dynamic programming
- 18.6 Greedy algorithms and intervals
- 18.7 Backtracking and combinatorial search
- 18.8 Two pointers, sliding windows and prefix sums
- 18.9 Interview problem-solving and common patterns
Key terms
18.1 Big-O and complexity analysis
- Big-O
- Upper bound on growth rate
- O(log n)
- Logarithmic growth, as in halving or doubling
- O(n log n)
- Typical of efficient comparison sorts
- Amortized cost
- Average cost over many operations
- Big-Θ
- A tight bound, above and below
- Auxiliary space
- Extra memory beyond the input
- Recurrence
- A cost defined in terms of smaller inputs
18.2 Searching and binary search
- Lower bound
- First index ≥ target
- Upper bound
- First index > target
- Binary search on the answer
- Bisecting a monotonic feasibility check
- Monotonic predicate
- False, then true from some point
- Exponential search
- Doubling to find a range, then bisecting
18.3 Sorting algorithms
- Binary search
- Halving search on sorted data
- Merge sort
- Stable divide-and-conquer sort
- Quicksort
- Partition-based sort with O(n log n) average
- Stable sort
- Keeps the order of equal elements
- Timsort
- Hybrid merge and insertion sort
- Introsort
- Quicksort falling back to heapsort
- Radix sort
- Sorts digit by digit
- External sort
- Sorting data bigger than memory
18.4 Recursion and divide and conquer
- Base case
- Condition that stops recursion
- Dynamic programming
- Reusing overlapping subproblem results
- Memoization
- Caching results of function calls
- Greedy algorithm
- Choosing the locally best option each step
- Divide and conquer
- Split, solve, combine
- Master theorem
- Solves T(n) = aT(n/b) + f(n)
- Tail call
- A call that's the function's last action
- Fast exponentiation
- Squaring to compute powers
18.5 Dynamic programming
- Optimal substructure
- Best solution built from best sub-solutions
- Overlapping subproblems
- The same subproblems recur
- Tabulation
- Bottom-up DP table filling
- Knapsack
- Choosing items under a weight limit
- Edit distance
- Minimum insert, delete or substitute steps
- Kadane's algorithm
- Maximum subarray in O(n)
18.6 Greedy algorithms and intervals
- Exchange argument
- Shows swapping in the greedy choice is safe
- Interval scheduling
- Choosing non-overlapping intervals
- Sweep line
- Processing sorted events in order
- Earliest deadline first
- Orders jobs by deadline
18.7 Backtracking and combinatorial search
- Backtracking
- Build candidates step by step, undoing dead ends
- Pruning
- Skipping branches that can't succeed
- Branch and bound
- Prunes using a bound on the best value
- Constraint satisfaction
- Assigning values that satisfy constraints
- Meet in the middle
- Solve halves separately and combine
18.8 Two pointers, sliding windows and prefix sums
- Slow and fast pointers
- One index writes, one reads
- Difference array
- Range updates in O(1)
- Dutch national flag
- Three-way partition in one pass
18.9 Interview problem-solving and common patterns
- Two pointers
- Moving two indices through data to avoid nested loops
- Prefix sum
- Running totals for fast range sums
- Brute force
- Trying all possibilities directly
- Edge case
- Unusual input at the boundaries of a problem
- Constraint hint
- Input size suggests the complexity needed
- Boyer–Moore vote
- Majority element in O(1) space
- Fisher–Yates
- Uniform in-place shuffle
- Online algorithm
- Processes input as it arrives
- Coordinate compression
- Maps values to small indexes
Sample practice questions
What does Big-O notation describe?
- An upper bound on how time or memory grows with input size
- The number of lines of code an algorithm needs
- The amount of memory the computer has installed
- The exact number of seconds a program takes to finish
Answer: A. An upper bound on how time or memory grows with input size O(2n) and O(n) are the same class.
What does binary search require, and what is its complexity?
- A linked list as input; O(log n)
- A sorted collection; O(log n)
- A hash table as input; O(n)
- Any collection at all; O(1)
Answer: B. A sorted collection; O(log n) Binary search on a linked list loses its advantage because there's no O(1) indexing.
What is the lower bound for comparison-based sorting in the worst case?
- Ω(n log n)
- Ω(n²)
- Ω(n)
- Ω(log n)
Answer: A. Ω(n log n) Counting and radix sort beat it by not comparing elements.
What does every correct recursive function need?
- A loop inside the function body, around the call
- At least two parameters, one being a counter
- A base case, and a step that moves toward it
- A global variable to track the recursion depth
Answer: C. A base case, and a step that moves toward it Without a base case it overflows the stack.
Why is naive recursive Fibonacci slow? ```python def fib(n): return n if n < 2 else fib(n - 1) + fib(n - 2) ```
- Adding very large numbers together is extremely slow
- It secretly runs a nested loop on every recursive call
- It recomputes the same subproblems, taking exponential time
- Most languages can't handle recursion more than a few levels deep
Answer: C. It recomputes the same subproblems, taking exponential time Memoization or a bottom-up loop makes it O(n).
What is a greedy algorithm?
- One that always sorts its input before doing anything
- One taking the locally best choice each step, hoping it's globally best
- One that uses as much memory as possible to save time
- One that tries every possible combination exhaustively
Answer: B. One taking the locally best choice each step, hoping it's globally best Greedy coin change works for US coins but not for every coin system.
What is backtracking?
- Building candidates stepwise and abandoning dead-end paths early
- Running an algorithm in reverse from its output to its input
- Sorting an array starting from its last element instead
- Undoing a series of commits in Git to restore older code
Answer: A. Building candidates stepwise and abandoning dead-end paths early Used for permutations, N-Queens and Sudoku solvers.
Which technique finds a pair summing to a target in a sorted array in O(n) time and O(1) space?
- Two pointers from each end, moving inward by the sum
- Sorting the array again in descending order first
- Nested loops that check every possible pair of values
- A recursive search through every possible subset
Answer: A. Two pointers from each end, moving inward by the sum Move the left pointer up if the sum is too small, the right one down if too big.
You need the k most frequent words in a large list. Which approach is efficient?
- Compare every word against every other word
- Count in a hash map, then keep a size-k heap
- Sort all the words alphabetically, then scan
- Binary search the unsorted list for each word
Answer: B. Count in a hash map, then keep a size-k heap Counting is O(n); the heap step is O(n log k).
What is the time complexity of this code? ```python for i in range(n): for j in range(n): total += i * j ```
- O(log n)
- O(n²)
- O(n)
- O(2n)
Answer: B. O(n²) Two nested loops of n iterations each give n × n steps.
More Server Side
- HTTP fundamentals
- REST API design
- GraphQL
- gRPC & real-time APIs
- OAuth 2.0, OIDC & JWT
- Sessions, cookies & web app security
- C# & .NET
- Java & Spring Boot
- Node.js & Express
- Python, Django & FastAPI
- Go (Golang)
- Concurrency & multithreading
- OOP & SOLID
- Design patterns
- Dependency injection
- Logging & observability
- Data structures
- Linux & shell scripting