Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms, Algorithmic Thinking and Structured Code.

Similar presentations


Presentation on theme: "Algorithms, Algorithmic Thinking and Structured Code."— Presentation transcript:

1 Algorithms, Algorithmic Thinking and Structured Code

2

3 Tell me how to make a Jam Sandwich

4

5 Tell me how to draw this tree (write the instructions in Simple English)

6

7 Tell me how to count the money in my right pocket (write the instructions in Simple English)

8

9 Origins of Algorithms Edsger Wybe Dijkstra

10

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

12

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

14

15 “Go to the other side of the road” “Go to Hell” Meaningful Instructions Effective

16

17 Meaningful Instructions Unambiguous A wedding journalist reported that the four bridesmaids wore the same dress.

18

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

20

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

22

23 “peel the potatoes” Halting

24

25

26

27 “peel the potatoes” IF number of peeled potatoes is not sufficient THEN peel a potato

28

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

30

31 “peel the potatoes” Instruction Blocks WHILE condition is true DO action1 action2 action3 END WHILE

32

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

34

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

36

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

38

39 Computational Thinking - 1

40

41 Computational Thinking – 2 (Eight Coins Puzzle)

42

43

44

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

46

47 Music Algorithmic?

48

49 get the potato basket from the cellar, get the pan from the cupboard, peel the potatoes return the basket to the cellar

50

51 I Have A Lovely Bunch Of Coconuts

52

53 x = 5 Y = 3 Temp = X X = Y Y = Temp

54

55 Computational Thinking – 3 Eight Coins Puzzle

56


Download ppt "Algorithms, Algorithmic Thinking and Structured Code."

Similar presentations


Ads by Google