Algorithms and Programming
The Algorithms and Programming domain tests algorithm design, control structures, variables, functions, searching and sorting, and debugging. Questions often ask you to trace pseudocode or choose the most efficient approach.
Algorithm basics
An algorithm is a finite, unambiguous sequence of steps that solves a problem. Core control structures are sequence, selection, and iteration. Variables store values; functions group reusable logic and accept parameters. Pseudocode is language-independent, so trace it exactly rather than assuming a particular language’s behavior.
Searching, sorting, and debugging
Linear search checks items one by one. Binary search is faster on sorted data because it repeatedly halves the search space. Common sorts include selection, insertion, and merge sort. Debugging uses tracing, print statements, test cases, and boundary checks.
Worked example
Search the sorted list 2, 5, 8, 12, 16, 23, 38, 56, 72, 91 for 23 using binary search. Index the list 0–9. Midpoint 4 holds 16; 23 is larger, so search indices 5–9. Midpoint 7 holds 56; 23 is smaller, so search 5–6. Midpoint 5 holds 23: found in three comparisons. Linear search would check six values.
Traps
Binary search requires sorted data. Watch off-by-one errors in loop bounds. In many languages, = assigns and == compares. An iteration must change the condition variable or it may loop forever. Recursion needs a base case. Do not assume pseudocode uses short-circuit evaluation unless stated.