OSAT Computer Science (OK181) study materials
OSAT Computer Science (OK181) study resources

OSAT Computer Science (OK181): Programming Fundamentals and Algorithm Design

OSAT Computer Science (OK181) · Work through your exam, one topic at a time.

All guide sections

Programming Fundamentals and Algorithm Design

What Domain 2 tests

Programming Fundamentals and Algorithm Design covers how a solution is expressed and checked: variables and types, control structures, functions and parameters, scope, recursion, pseudocode, tracing, debugging, and basic algorithm design. The exam favors code reading and output prediction over syntax trivia.

Core rules

  • A variable has a name, type, and scope. Assignment changes state; equality comparison asks a question. Do not confuse = with ==.
  • Sequence, selection, and iteration are the three control structures. A pretest loop checks its condition before each iteration, so a loop whose condition starts false executes zero times.
  • Functions should have one job, a clear return value, and documented parameters. Passing a primitive usually copies the value; passing an object reference can expose the same underlying data.
  • Recursion needs a base case that stops the calls and a recursive case that moves toward it.
  • Trace with a table of variable values, not by guessing. Boundary tests (empty, one item, maximum) catch off-by-one errors.

Worked example

Trace this pseudocode with n = 10:

c = 0
while n > 0
    n = n / 2 using integer division
    c = c + 1
return c

Start: n = 10, c = 0. Iteration 1: n = 5, c = 1. Iteration 2: n = 2, c = 2. Iteration 3: n = 1, c = 3. Iteration 4: n = 0, c = 4. The loop stops, so the function returns 4.

Traps

Integer division truncates (7 / 2 gives 3), which changes loop counts. Short-circuit evaluation can skip a function call on the right side of AND/OR. A local variable does not modify a same-named global unless the language says so. Recursive code without progress toward the base case overflows the call stack.