Section 4 Algorithmic Thinking
Section 4 Algorithmic Thinking
ALGORITHMIC THINKING
ENGR 112 – Introduction to Engineering Computing
2 Algorithmic Thinking
Algorithmic thinking:
The ability to identify and analyze problems, and to
develop and refine algorithms for the solution of those
problems
Algorithm:
Detailed step-by-step procedure for the performance of
a task
Learning to program is about developing
algorithmic thinking skills, not about learning a
programming language
Pseudocode
Natural language
Not necessarily language-independent
K. Webb ENGR 112
5 Flowcharts
Start/End
Always indicate the start and end of any
flowchart
Process
Indicates the performance of some
action
Conditional
Performs a check and makes a decision
Binary result: True/False, Yes/No, 1/0
Algorithm flow branches depending on
result
Input/Output
Input or output of variables or data
K. Webb ENGR 112
Flowchart – Example
8
Then, move on to do C
== Equal to x == b
~= Not equal to k ~= 0
< Less than t < 12
> Greater than a > -5
<= Less than or equal to 7 <= f
>= Greater than or equal to (4+r/6) >= 2
NOT– negates the logical value of an
~ expression
~(b < 4*g)
AND – both expressions must evaluate to
&& true for result to be true
(t > 0)&&(c == 5)
OR – either expression must evaluate to true
|| for result to be true
(p > 1)||(m > 3)
Let 𝑥𝑥 = 12 and 𝑦𝑦 = −3
Consider the following logical expressions:
Logical Expression Value
𝑥𝑥 + 𝑦𝑦 == 15 0
𝑦𝑦 == 2 || 𝑥𝑥 > 8 1
~ 𝑦𝑦 < 0 0
𝑥𝑥 == 12 &&~(𝑦𝑦 ≥ 5) 1
Consider a
piecewise linear
function of 𝑥𝑥
𝑦𝑦 = 𝑓𝑓(𝑥𝑥) not
defined by a single
function
Function depends
on the value of 𝑥𝑥
Can implement
with an
if … elseif … else
structure
count x x x
0 5 16 0.8
1 2.5 8 -
2 1.25 4 -
3 0.625 2 -
4 - 1 -
5 - - -
i x(i) x
1 1 [1]
2 4 [1, 4]
3 9 [1, 4, 9]
4 16 [1, 4, 9, 16]
5 25 [1, 4, 9, 16, 25]
−2 1
𝐵𝐵 = 0 8
7 −3
Generate a matrix 𝐶𝐶
whose entries are the
squares of all of the
elements in 𝐵𝐵
Nested for loop
Outer loop steps through
rows
Counter is row index
Inner loop steps through
columns
Counter is column index
K. Webb ENGR 112
49 Pseudocode & Top-Down Design