Tutorial 2: Problems, Algorithms, and Procedures

Unit 1 ยท Section 2

Objectives

An algorithm is a finite, precise procedure that transforms input into output. Good specifications state assumptions and edge cases before implementation. Pseudocode separates logic from language syntax.

read values
set largest to first value
for each remaining value
    if value > largest, update largest
output largest

Exercises

  1. Write pseudocode for finding a minimum.
  2. Identify input, output, and constraints for average marks.
  3. Trace your algorithm with empty, one-item, and repeated inputs.

Self-check

  1. What makes a procedure unambiguous?
  2. Why state constraints?
  3. What is tracing?

Self-Check Quiz

1. Must an algorithm terminate?

AnswerYes, an algorithm is expected to finish for valid inputs.

2. What is an output?

AnswerThe result produced by applying the procedure to its input.

Homework

  1. Specify and trace a grade-classification algorithm.
  2. Include boundary and invalid cases.
  3. Explain how tests support confidence.
Sample answerInputs are marks constrained to 0..100; outputs are named categories. Tests include 0, 49, 50, 79, 80, 100, and invalid values. Tracing records state after each decision.