Programming and Algorithms
What to know
Programming questions reward precise reading of code and invariants. Know variables, types, scope, parameter passing, return values, control flow, exceptions, and modular design. For data structures, compare arrays, linked lists, stacks, queues, trees, graphs, and hash tables by access, search, insertion, and deletion costs. Algorithms: linear and binary search, selection/insertion/merge/quick sorts, recursion versus iteration, and Big-O growth. Be able to trace a loop, count operations, identify a base case, and explain tradeoffs between time and space. Debugging concepts include test cases, boundary values, and reproducible failures.
Traps
Classic errors are off-by-one loop bounds, using = where == belongs, forgetting a recursive base case, and assuming binary search works on unsorted data. Short-circuit evaluation can hide a side effect: in A and B, B is not evaluated when A is false. Pass-by-value copies a primitive, while passing an object reference can let a method mutate shared state. Also check whether a question asks for worst case, average case, or best case.
Worked example
Search for 7 in the sorted list [1, 3, 5, 7, 9, 11, 13, 15]. Choose the lower middle element 7 and stop after one comparison. To search for 15, compare 7, then 11, then 13, then 15: four comparisons. Rule of thumb: binary search halves the remaining candidates, so worst-case comparisons are about log2(n)+1; it requires sorted data and random access.