Algorithm-to-Program Development · Lesson 2 of 3
From Algorithm to Program
Implement an algorithm by preserving its control flow and data meaning. Translate assignments, decisions, loops and subprograms into the chosen language, checking its index and type conventions. Test small parts as they are added.
By the end, you can
- Translate pseudocode into a high-level programming language.
- Preserve algorithmic logic when implementing.
- Use appropriate variables, selection and iteration.
Implementation
Implementation is translating the pseudocode into a real language. Done properly it is mechanical, because every decision was made in the design.
The structures map directly. An assignment arrow becomes the language’s assignment operator. IF, ELSE and ENDIF become the language equivalents. FOR, WHILE and REPEAT UNTIL each have a counterpart, though the exact form differs — a REPEAT UNTIL condition becomes a loop that runs while the condition is false, which flips the test and is a classic place to introduce a bug.
Three details need attention because languages differ. Array indexes may start at 0 or at 1, and the pseudocode range has to be adjusted rather than copied. Input arrives as text and must be converted before arithmetic. Integer division may be a separate operator or may happen silently when both operands are whole numbers.
Preserve the logic rather than improving it while typing. Changing the structure as you go — merging two loops, moving a condition, skipping a variable that seemed unnecessary — is how a traced and correct algorithm becomes an untested program. Keep the comments too, written with the language’s own commenting feature: // in pseudocode and Java, # in Python, and an apostrophe in Visual Basic.
Build it in pieces and run it as you go. Write the input and echo it back; run it. Add the processing for one case; run it. Add the loop; run it. A program written in full and run for the first time at the end presents every error at once, and they hide one another.
Worth remembering
- Each pseudocode structure has a direct counterpart in the language.
- Watch index bases, string-to-number conversion and integer division.
- Build and run in small pieces rather than typing the whole program first.
Worked example
A one-based pseudocode array may need careful adjustment in a language whose arrays start at zero.
Practice
Warm-up · not marked
Check your understanding
Answer in your own words, then compare with the worked answer. Nothing here is saved or scored.
Worked answer
The upper bound must be adjusted so that all five intended iterations occur.
Check your method, units and explanation against it.
Marked practice
Set 1 of 4 · easiest first · Checked as you go, with the worked answer. Sign in or create a free account to save your progress.