MEG 202 · Basic Software Engineering
Our notes
2 min readWhat an algorithm is
An algorithm is a finite sequence of precise steps that solves a problem. Properties:
- Finiteness: it ends after a finite number of steps.
- Definiteness: each step is clear and unambiguous.
- Input: zero or more inputs.
- Output: at least one result.
- Effectiveness: each step can actually be carried out.
Three control structures
Any algorithm can be built from (the structured programming theorem):
- Sequence: steps one after another.
- Selection: IF ... THEN ... ELSE.
- Iteration: loops (WHILE, REPEAT ... UNTIL, FOR).
Pseudocode and flowcharts
Pseudocode writes the algorithm in structured English. Flowcharts draw it with standard symbols: oval (start/stop), parallelogram (input/output), rectangle (process), diamond (decision), arrows (flow).
Stepwise refinement (top-down design)
Proposed by Niklaus Wirth (1971): start with a general statement of the solution and repeatedly break each step into smaller, more detailed steps until each can be written directly in code.
Example: analyse shaft test data
Level 1:
Read the torque readings
Compute the statistics
Report the results
Level 2 (refining "Compute the statistics"):
sum ← 0; max ← first reading
FOR each reading r
sum ← sum + r
IF r > max THEN max ← r
mean ← sum / n
Each refined step is now simple enough to code.
Modularity
Divide a program into modules (functions, procedures, subroutines), each doing one well-defined job, with clear inputs and outputs.
Benefits:
- Easier to understand, write and test (each module separately).
- Reuse: a module to convert units or compute a mean can be used in many programs.
- Team work: different people write different modules.
- Easier maintenance: change one module without breaking the others.
Good modules have high cohesion (do one thing) and low coupling (depend little on each other); they communicate through parameters, not shared global variables.
Example: a module in C
double mean(double x[], int n) {
double sum = 0.0;
for (int i = 0; i < n; i++)
sum = sum + x[i];
return sum / n;
}
Trace with x = {2.0, 4.0, 9.0}, n = 3: sum goes 2, 6, 15; returns 15/3 = 5.0 ✓.
Exams usually ask
- State the properties of an algorithm.
- Develop an algorithm by stepwise refinement and draw its flowchart.
- Explain the benefits of modularity, with cohesion and coupling.
Common mistake
Writing pseudocode that is really vague English ("process the data"). Each step at the final level must be precise enough to translate directly into code.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Best pick Introduction to Computer Science, 3.2 Algorithm Design and Discovery
(opens openstax.org in a new tab)
OpenStax, Introduction to Computer Science, 3.2 Algorithm Design and Discovery, CC BY-NC-SA 4.0 · licence
-
Introduction to Computer Science, 2.1 Computational Thinking
(opens openstax.org in a new tab)
OpenStax, Introduction to Computer Science, 2.1 Computational Thinking, CC BY-NC-SA 4.0 · licence
-
Bottom-up and top-down approaches
(opens en.wikipedia.org in a new tab)
Wikipedia, Bottom-up and top-down approaches, CC BY-SA 4.0 · licence
-
Modular programming
(opens en.wikipedia.org in a new tab)
Wikipedia, Modular programming, CC BY-SA 4.0 · licence
-
NOUN CIT 215: Introduction to Programming Language
NOUN course book (PDF, about 6.2 MB: best on Wi-Fi). Syntax, semantics and translation.
(opens nou.edu.ng in a new tab)
-
NOUN CIT 237: Programming and Algorithms
NOUN course book (PDF, about 1.6 MB). Designing and writing algorithms.
(opens nou.edu.ng in a new tab)
-
OpenStax, Introduction to Computer Science (whole free textbook)
The whole book, free to read online or download as a PDF (the PDF is large: Wi-Fi).
(opens openstax.org in a new tab)
OpenStax, OpenStax, Introduction to Computer Science (whole free textbook), CC BY-NC-SA 4.0 · licence
Watch
-
Design and Analysis of Algorithms Unit II Stepwise Refinement Part II
14 min · ≈ 63 MB · about ₦35
(opens youtube.com in a new tab)
-
Stepwise Refinement, Decomposition & Top-Down Design | AS Level CS | CS with ZAK
3 min · ≈ 14 MB · about ₦8
(opens youtube.com in a new tab)
-
Top Down, Stepwise Refinement of Case Study | Ep. 90 | C Programming Language
3 min · ≈ 14 MB · about ₦8
(opens youtube.com in a new tab)
-
Designing Algorithms
9 min · ≈ 41 MB · about ₦23
(opens youtube.com in a new tab)
-
Christo Ananth - Stepwise Refinement Techniques. Modular programming - Data Structures
32 min · ≈ 144 MB · about ₦81
(opens youtube.com in a new tab)
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.