algorithms, algorithmic thinking and structured code
TRANSCRIPT
![Page 1: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/1.jpg)
Algorithms,
Algorithmic Thinking and
Structured Code
![Page 2: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/2.jpg)
![Page 3: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/3.jpg)
Tell me how to make a Jam Sandwich
![Page 4: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/4.jpg)
![Page 5: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/5.jpg)
Tell me how to draw this tree (write the instructions in Simple English)
![Page 6: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/6.jpg)
![Page 7: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/7.jpg)
Tell me how to count the money in my right pocket (write the instructions in Simple English)
![Page 8: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/8.jpg)
![Page 9: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/9.jpg)
Origins of Algorithms
Edsger Wybe Dijkstra
![Page 10: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/10.jpg)
![Page 11: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/11.jpg)
Spaghetti Code mov eax,3
mov ebx,3
L1: decjmpreg eax,L2
decjmpreg ebx,L3
jmp L1
L2: eax = 0
decjmpreg ebx, L4
jmp L5
L3: ebx = 0
inc eax
decjmpreg eax, L4
jmp L5
L4: mov eax,0
hlt
L5: mov eax,1
hlt
![Page 12: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/12.jpg)
![Page 13: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/13.jpg)
“Peeling Potatoes for a Family Supper”
We observe the cook doing this
“He gets the potato basket from the cellar,
gets the pan from the cupboard,
peels the potatoes
returns the basket to the cellar”
Sequence
![Page 14: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/14.jpg)
![Page 15: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/15.jpg)
“Go to the other side of the road”
“Go to Hell”
Meaningful Instructions
Effective
![Page 16: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/16.jpg)
![Page 17: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/17.jpg)
Meaningful Instructions
Unambiguous
A wedding journalist reported that the four bridesmaids wore the same dress.
![Page 18: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/18.jpg)
![Page 19: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/19.jpg)
Instructions
“He gets the potato basket from the cellar,
gets the pan from the cupboard,
peels the potatoes
returns the basket to the cellar”
get the potato basket from the cellar,
get the pan from the cupboard,
peel the potatoes
return the basket to the cellar
Sequence: Correct Order
![Page 20: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/20.jpg)
![Page 21: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/21.jpg)
Jordan does something different
get the potato basket from the cellar,
get the pan from the cupboard,
IF clothes are light colored THEN put on an apron
peel the potatoes
return the basket to the cellar
IF some condition THEN some action
Selection
![Page 22: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/22.jpg)
![Page 23: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/23.jpg)
“peel the potatoes”
Halting
![Page 24: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/24.jpg)
![Page 25: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/25.jpg)
![Page 26: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/26.jpg)
![Page 27: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/27.jpg)
“peel the potatoes”
IF number of peeled potatoes is not sufficient THEN peel a potato
IF number of peeled potatoes is not sufficient THEN peel a potato
IF number of peeled potatoes is not sufficient THEN peel a potato
IF number of peeled potatoes is not sufficient THEN peel a potato
IF number of peeled potatoes is not sufficient THEN peel a potato
![Page 28: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/28.jpg)
![Page 29: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/29.jpg)
“peel the potatoes”
WHILE the number of potatoes is insufficient DO peel a potato
get the potato basket from the cellar,
get the pan from the cupboard,
IF clothes are light colored THEN put on an apron
WHILE the number of potatoes is insufficient DO peel a potato
return the basket to the cellar
WHILE condition is true DO an action
Iteration
![Page 30: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/30.jpg)
![Page 31: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/31.jpg)
“peel the potatoes”
Instruction Blocks
WHILE condition is true DO
action1
action2
action3
END WHILE
![Page 32: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/32.jpg)
![Page 33: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/33.jpg)
Algorithms – a definition
• Sequence of Instructions (ordered)
• Instructions are Effective and Unambigous
• Sequence must Halt in a finite time
• On halting, the sequence must have a Result
• Instructions may be
• Simple Actions
• Selections
• Iterations
action
IF condition THEN action
WHILE condition is true DO action
![Page 34: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/34.jpg)
![Page 35: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/35.jpg)
Pseudo-code for Structured Programming
WHILE condition is true
action
action
END WHILE
DO
action
action
WHILE condition is true
IF condition is true
action
action
END IF
actions
move robot forward by 20 cm
get a coin from your pocket
press a key on your phone
conditions
robot sensor shows obstacle
coin is a 50p
pocket is empty
key pressed is 7
compound conditions
NOT condition1
condition1 AND condition2
condition1 OR condition2
actions
add, subtract, multiply, divide
get, put (set)
conditions
equals
less than, greater than
combi’s of above
![Page 36: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/36.jpg)
![Page 37: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/37.jpg)
Pseudo-code Examples
1. Robot moves forward until senses obstacle
2. Check that you have typed in a password that ends with 5
3. Check that you have entered a 6-digit phone number
![Page 38: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/38.jpg)
![Page 39: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/39.jpg)
Computational Thinking - 1
![Page 40: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/40.jpg)
![Page 41: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/41.jpg)
Computational Thinking – 2
(Eight Coins Puzzle)
![Page 42: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/42.jpg)
![Page 43: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/43.jpg)
![Page 44: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/44.jpg)
![Page 45: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/45.jpg)
Dr.C’s “Atomic Language” Conjecture(weak version)
Any computer program can be expressed using only the following:
•Declaration: as many variable you need
•Just 2 Operations:
•One loop construct:
We do not need:
IF condition THEN action
FOR loop
Operations of multiplication, division and anything else.
WHILE condition action actionEND WHILE
add1 to a variablesubtract 1 from a variable
![Page 46: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/46.jpg)
![Page 47: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/47.jpg)
Music
Algorithmic?
![Page 48: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/48.jpg)
![Page 49: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/49.jpg)
get the potato basket from the cellar,
get the pan from the cupboard,
peel the potatoes
return the basket to the cellar
![Page 50: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/50.jpg)
![Page 51: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/51.jpg)
I
Have
A
Lovely
Bunch
Of
Coconuts
![Page 52: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/52.jpg)
![Page 53: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/53.jpg)
x = 5
Y = 3
Temp = X
X = Y
Y = Temp
![Page 54: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/54.jpg)
![Page 55: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/55.jpg)
Computational Thinking – 3
Eight Coins Puzzle
![Page 56: Algorithms, Algorithmic Thinking and Structured Code](https://reader033.vdocuments.us/reader033/viewer/2022052913/56649e4d5503460f94b432da/html5/thumbnails/56.jpg)