Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer programming IV. Algorithms.

Similar presentations


Presentation on theme: "Computer programming IV. Algorithms."— Presentation transcript:

1 Computer programming IV. Algorithms

2 Recap: What is computer programming?
Telling computers to solve a problem Solve problem and come up with solution (algorithm) Break down the problem into step by step solution Write the solution in a programming language (coding)

3 Computer Programming repetition
Algorithm for going to school in the morning sequencing conditional logic

4 Algorithms: Decision tree Pattern recognition Divide and conquer

5 Algorithm: Decision Trees (Harry Potter's sorting hat)
Person Hair Length Teacher? Brave things Likes Muggles? Medieval wizards? House Harry short no 20 yes Gryffindor Draco long 4 Slytherin Ron 15 Snape 16 Hermione 25 Pansy 17 McGonagall Ginny 18 Millicent 6 Merlin 50 Blaise 8 ??? Salazar 30

6 Algorithm: Decision Trees
? ? >= 15 brave things < 15 brave things Train: 7 of 10 correct (70% correct) Slytherin Test: 1 of 2 correct (50% correct) Gryffindor

7 Algorithm: Decision Trees
? ? Likes Muggles Doesn’t like Muggles Non Medieval Wizards Medieval Wizards Slytherin Test: 2 of 2 correct (100% correct) Gryffindor Slytherin

8 Algorithm: Decision Trees
Guess a number between 0 and 3: X > 1? X > 0? X > 2? X = 0 X = 1 X = 2 X = 3 no yes

9 Coding: Decision Trees
Guess a number between 0 and 3: If X > 1 then: If X > 2 then: X = 3 Else: X = 2 If X > 0 then: X = 1 X = 0 X > 1? X > 0? X > 2? X = 0 X = 1 X = 2 X = 3 no yes

10 Algorithm: Pattern Recognition
Rock-Paper-Scissors: Human VS Computer The computer guesses what we are going to do next based on the patterns of our previous throws

11 Algorithm: Pattern Recognition
bakaji bavwa bamona bana The women saw the children

12 Algorithm: Pattern Recognition
The child: muana The children: bana The woman: mukaji The women: bakaji The man: muluma The men: baluma The lion: ntambwe The lions: bantambwe The small lions: tubantambwe The small lion: kantambwe Saw: mumona/bamona/tumona/kamona

13 Algorithm: Sorting We sort things all the time! Packing, moving, ...
How can we teach computers how to sort things?

14 Algorithm: Selection sort
While there is still some heights to be sorted: Select the shortest from the set and put it to one side 45

15 Algorithm: Divide &Conquer Quick Sort
While the group has more than 1 object Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups

16 Algorithm: Quick Sort 9

17 Algorithm: Quick Sort 9

18 Algorithm: Quick Sort 16

19 Algorithm: Quick Sort 16

20 Algorithm: Quick Sort 19

21 Algorithm: Quick Sort 19

22 Algorithm: Quick Sort 19

23 Algorithm: Quick Sort 19 While the group has more than 1 object
Pick one object at random, put objects shorter than it on its left and objects taller than it on its right Repeat this same procedure on the left and right groups 19

24 Coding: Choose Your Own Adventure
Use scratch.mit.edu Create backdrops Create scenes Match scenes to backdrops Code the choices

25 Coding: Robot Singing Use

26 Algorithm: Divide & Conquer Tower of Hanoi
Think how we can use divide and conquer to solve the problem: Tower of Hanoi ( Next week: Building your own website!

27 Questions?


Download ppt "Computer programming IV. Algorithms."

Similar presentations


Ads by Google