ENG 213.1 · Computer Programming for Engineers
Our notes
1 min readAlgorithm
An algorithm is a finite list of clear steps that solves a problem. A good algorithm is:
- Finite: it stops.
- Definite: each step has one meaning.
- Has input and output.
- Effective: each step can be carried out.
- General: works for a whole class of inputs, not one case.
Steps in solving a problem by computer
- Define the problem: inputs, outputs, formulas, units.
- Design the algorithm (flowchart or pseudocode).
- Code it in a language.
- Compile and test with known answers.
- Debug and document.
Flowchart symbols
| Symbol | Use |
|---|---|
| Oval | start / stop |
| Parallelogram | input / output |
| Rectangle | process (calculation) |
| Diamond | decision (yes / no) |
| Arrow | flow direction |
| Circle | connector |
The three control structures
- Sequence: one step after another.
- Selection: IF condition THEN ... ELSE ...
- Repetition: repeat a block a fixed number of times or while a condition holds.
Worked example: roots of a quadratic
Pseudocode:
- Input a, b, c.
- d = b² − 4ac.
- If d > 0: x1 = (−b + √d)/(2a), x2 = (−b − √d)/(2a); print both.
- Else if d = 0: x = −b/(2a); print "equal roots", x.
- Else: print "complex roots".
- Stop.
Test: a = 1, b = −3, c = 2: d = 9 − 8 = 1, x1 = (3 + 1)/2 = 2, x2 = (3 − 1)/2 = 1. Check: 2² − 3(2) + 2 = 0 ✓.
Worked example: largest of N readings
- Input N and the first reading; set MAX = first reading.
- Repeat N − 1 times: input the next reading R; if R > MAX then MAX = R.
- Print MAX.
Trace with 4.2, 6.1, 5.0, 6.8, 3.9: MAX goes 4.2 → 6.1 → 6.1 → 6.8 → 6.8. Output 6.8.
Dry run (desk check)
Before coding, trace the algorithm by hand with a table of variables. It catches logic errors cheaply.
Exams usually ask
- Define an algorithm and give its properties.
- Draw a flowchart or write pseudocode for a stated engineering calculation.
Common mistake
Forgetting the case a = 0 in the quadratic (division by zero). Good algorithms check for impossible inputs.
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
-
Algorithm
(opens en.wikipedia.org in a new tab)
Wikipedia, Algorithm, CC BY-SA 4.0 · licence
-
Flowchart
(opens en.wikipedia.org in a new tab)
Wikipedia, Flowchart, CC BY-SA 4.0 · licence
-
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
-
NPTEL: Problem Solving through Programming in C (IIT Kharagpur, whole course)
Algorithms, flowcharts and pseudocode, then variables, decisions, loops, arrays and functions in C (the ideas carry over to Fortran and Python). Video lectures, many hours in all: watch on Wi-Fi where you can.
(opens nptel.ac.in in a new tab)
NPTEL, NPTEL: Problem Solving through Programming in C (IIT Kharagpur, whole course), CC BY-NC-SA 4.0 · licence
Watch
-
Flow chart to psuedocode (computer)
7 min · ≈ 32 MB · about ₦18
(opens youtube.com in a new tab)
-
Flowchart Pseudocode and Algorithm Explained (How They Work Together)
14 min · ≈ 63 MB · about ₦35
(opens youtube.com in a new tab)
-
Algorithm, Pseudo code and Flowchart | Programming 101
17 min · ≈ 77 MB · about ₦43
(opens youtube.com in a new tab)
-
Algorithm Vs Flowchart Vs Pseudocode | Difference Between Algorithm And Flowchart | Intellipaat
7 min · ≈ 32 MB · about ₦18
(opens youtube.com in a new tab)
-
Flowchart tutorial
11 min · ≈ 50 MB · about ₦28
(opens youtube.com in a new tab)
-
Algorithm and Flowchart
57 min · ≈ 257 MB · about ₦144
(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.