Computer programming IV. Algorithms
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)
Computer Programming repetition Algorithm for going to school in the morning sequencing conditional logic https://www.tynker.com/blog/articles/ideas-and-tips/how-to-explain-algorithms-to-kids/
Algorithms: Decision tree Pattern recognition Divide and conquer
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 https://www.women.cs.cmu.edu/Who/Photos/Spring2017_DecisionTrees/
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 https://upload.wikimedia.org/ http://harrypotter.wikia.com
Algorithm: Decision Trees ? ? Likes Muggles Doesn’t like Muggles Non Medieval Wizards Medieval Wizards Slytherin Test: 2 of 2 correct (100% correct) Gryffindor Slytherin
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
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
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 http://www.nytimes.com/interactive/science/rock-paper-scissors.html
Algorithm: Pattern Recognition bakaji bavwa bamona bana The women saw the children
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
Algorithm: Sorting We sort things all the time! Packing, moving, ... How can we teach computers how to sort things?
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
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
Algorithm: Quick Sort 9
Algorithm: Quick Sort 9
Algorithm: Quick Sort 16
Algorithm: Quick Sort 16
Algorithm: Quick Sort 19
Algorithm: Quick Sort 19
Algorithm: Quick Sort 19
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
Coding: Choose Your Own Adventure Use scratch.mit.edu Create backdrops Create scenes Match scenes to backdrops Code the choices
Coding: Robot Singing Use http://www.edwareapp.com/
Algorithm: Divide & Conquer Tower of Hanoi Think how we can use divide and conquer to solve the problem: Tower of Hanoi (https://www.mathsisfun.com/games/towerofhanoi.html) Next week: Building your own website!
Questions?