Download presentation
Presentation is loading. Please wait.
Published byTiffany Day Modified over 9 years ago
1
Algorithms, Algorithmic Thinking and Structured Code
3
Tell me how to make a Jam Sandwich
5
Tell me how to draw this tree (write the instructions in Simple English)
7
Tell me how to count the money in my right pocket (write the instructions in Simple English)
9
Origins of Algorithms Edsger Wybe Dijkstra
11
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
13
“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
15
“Go to the other side of the road” “Go to Hell” Meaningful Instructions Effective
17
Meaningful Instructions Unambiguous A wedding journalist reported that the four bridesmaids wore the same dress.
19
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
21
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
23
“peel the potatoes” Halting
27
“peel the potatoes” IF number of peeled potatoes is not sufficient THEN peel a potato
29
“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
31
“peel the potatoes” Instruction Blocks WHILE condition is true DO action1 action2 action3 END WHILE
33
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
35
Pseudo-code for Structured Programming WHILE condition is true action END WHILE DO action WHILE condition is true IF condition is true 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
37
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
39
Computational Thinking - 1
41
Computational Thinking – 2 (Eight Coins Puzzle)
45
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 END WHILE add1 to a variable subtract 1 from a variable
47
Music Algorithmic?
49
get the potato basket from the cellar, get the pan from the cupboard, peel the potatoes return the basket to the cellar
51
I Have A Lovely Bunch Of Coconuts
53
x = 5 Y = 3 Temp = X X = Y Y = Temp
55
Computational Thinking – 3 Eight Coins Puzzle
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.