Programming and Problem Solving Fundamentals
This domain tests problem decomposition and code tracing. Expect algorithms, flowcharts, pseudocode, variables, operators, control structures, functions, arrays, and error types.
Core rules and concepts
- An algorithm is a finite, ordered, unambiguous set of steps that solves a problem. Pseudocode expresses it in structured English.
- Flowchart symbols: oval for start/end, parallelogram for input/output, rectangle for process, diamond for decision, arrows for flow.
- A variable names a storage location whose value can change; a constant does not. Data types include integer, real, character, string, and Boolean.
- Operators: arithmetic (+ - * /), relational (< > <= >= == !=), logical (AND, OR, NOT). In many languages = assigns; == compares.
- Control structures: sequence, selection (if/else, switch), and iteration (while, for). A loop needs initialization, a condition, and an update.
- Functions take parameters and return a value; arrays store multiple values under one name using an index.
- Syntax errors break grammar; logical errors produce wrong results; runtime errors occur during execution.
Worked example
Algorithm to find the sum of the first n natural numbers: 1 Start. 2 Read n. 3 Set sum = 0 and i = 1. 4 While i <= n: sum = sum + i; i = i + 1. 5 Print sum. 6 Stop. For n = 4, the trace is sum = 1, 3, 6, 10; i becomes 5 and the loop ends. Reasoning: initialization sets a clean total, the condition controls repetition, and the update prevents an infinite loop.
Traps that cost marks
Do not use = for comparison in pseudocode. Do not put a process in a diamond. Forgetting to initialize sum or to increment i are common. Check off-by-one errors: while i <= n includes n; while i < n excludes it.