Problem Solving Methodology
Problem Solving Methodology
This domain tests algorithm design, flowchart symbols, pseudocode and tracing simple logic. An algorithm is a finite sequence of unambiguous steps that takes input, produces output and terminates. A flowchart is a graphical algorithm; pseudocode is a structured English-like notation independent of syntax.
Rules and symbols
- Oval: start/stop. Parallelogram: input/output. Rectangle: process. Diamond: decision. Arrow: flow. Circle: connector.
- Three control patterns: sequence, selection (if/if-else/switch) and iteration (while, do-while, for).
- Every loop needs initialization, a condition and an update; otherwise it may not terminate.
- Trace tables record variable values after each step.
Worked example
Algorithm for sum of first n natural numbers:
- Start.
- Read n.
- Set sum = 0 and i = 1.
- While i <= n, sum = sum + i and i = i + 1.
- Print sum.
- Stop. For n = 4: after iterations sum = 1, 3, 6, 10; output 10. The loop adds each integer once and stops when i becomes 5.
Traps
Using i < n instead of i <= n loses the last term. Forgetting sum = 0 gives garbage. A decision diamond has one entry and two exits. Pseudocode should not depend on C++ semicolons. A flowchart needs a terminator, not an arrow into nowhere.