Control flow and code tracing
Trace each statement in order, updating variables after every assignment. For loops, record the variable at the start and end of each iteration. Off-by-one errors often come from confusing inclusive and exclusive bounds. A function call creates its own scope; local variables do not affect the caller's copies unless passed by reference.
Check yourself: What is the value of each variable at the start of this iteration?
Arrays, lists, and linked structures
Array access by index is O(1); inserting into the middle of a dynamic array is O(n) due to shifting. A singly linked list supports O(1) insertion at the head but O(n) search. A stack is last-in-first-out; a queue is first-in-first-out. Choose the structure whose fast operations match the problem's access pattern.
Check yourself: Does this operation require shifting elements or traversing nodes?
Trees and binary search trees
In a binary search tree, left descendants store smaller keys and right descendants store larger keys. Search, insert, and delete are O(h) where h is the height. A balanced BST keeps h = O(log n); inserting sorted data into a plain BST produces height O(n). Inorder traversal of a BST yields keys in sorted order.
Check yourself: Does the BST property hold at every node after your operation?
Sorting and searching
Comparison-based sorting has a lower bound of Ω(n log n). Merge sort achieves O(n log n) worst case; quicksort achieves O(n log n) expected case but O(n²) worst case. Binary search on a sorted array requires O(log n) comparisons. Verify the array is sorted before applying binary search.
Check yourself: Is the input sorted, and are you halving the search space at each step?
Asymptotic complexity
O denotes an asymptotic upper bound, Ω a lower bound, and Θ a tight bound. Analyze the innermost loop's iteration count as a function of the outer loop's variable. Nested loops with independent ranges multiply; nested loops where the inner bound depends on the outer require a summation. Drop lower-order terms and constant factors.
Check yourself: Are you counting the total iterations across all loop passes, not just one pass?