Skip to content

Data Structures

Data StructuresKey Points
Primitive typesKnow how int, char, double, etc. are represented in memory and the primitive operations on them.
ArraysFast access for element at an index, slow lookups (unless sorted) and insertions. Be comfortable with notions of iteration, resizing, partitioning, merging, etc.
StringsKnow how strings are represented in memory. Understand basic operators such as comparison, copying, matching, joining, splitting, etc.
ListsUnderstand trade-offs with respect to arrays. Be comfortable with iteration, insertion, and deletion within singly and doubly linked lists. Know how to implement a list with dynamic allocation, and with arrays.
Stacks and queuesRecognize where last-in first-out (stack) and first-in first-out (queue) semantics are applicable. Know array and linked list implementations.
Binary treesUse for representing hierarchical data. Know about depth, height, leaves, search path, traversal sequences, successor/pre-decessor operations.
HeapsKey benefit: O(1) lookup find-max, O(logn) insertion, and O(logn) deletion of max. Node and array representations. Min-heap variant.
Hash tablesKey benefits: O(1) insertions, deletions, lookups; good for comparison of unordered date.
Key disadvantages: not suitable for order-related queries; need for resizing; poor worst-case performance.
Understand implementation using array of buckets and collision chains. Know hash functions for integers, strings, objects.

Algorithms

Algorithm typeKey points
SortingUncover some structure by sorting the input.
RecursionIf the structure of the input is defined in a recursive manner design, a recursive algorithm that follows the input definition.
Divide-and-conquerDivide the problem into two or more smaller independent sub-problems and solve the original problem using solutions to the sub-problems.
Dynamic programmingCompute solutions for smaller instances of a given problem and use these solutions to construct a solution to the problem. Cache for performance.
Greedy algorithmsCompute a solution in stages, making choices that are locally optimum at each step; these choices are never undone.
InvariantsIdentify an invariant and use it to rule out potential solutions that are sub-optimal or dominated by other solutions.
Graph modelingDescribe the problem using a graph and solve it using an existing graph algorithm.

Logical Principles

PrincipleKey points
Concrete ExamplesManually solve concrete instance and then build a general solution. Start with small inputs (e.g., few elements) and extremal inputs (e.g., sorted)
Case analysisSplit the input/execution into a number of cases and solve each case in isolation.
Iterative refinementMost problems can be solved using a brute-force approach. Find such a solution and improve upon it.
ReductionUse a known solution to some other problem as a sub-routine.