SlideShare uma empresa Scribd logo
1 de 35
Learn to
Think Like A Coder
Andrew Marks
@entreprenerds
“Everybody should learn how to program a
computer because it teaches you how to think.”
- Steve Jobs
Six Reasons a Non-Computer Nerd
Might Want to Learn to Code
1. It's like learning to read or write
2. It's useful, even outside of computer geek
circles
3. It's helps you talk to actual programmers
4. It's actually a fun hobby
5. Computers are a part of society
6. It teaches other skills
A coder is going to the grocery store and his
partner asks him, “Would you buy a bottle of
milk, and if there are eggs, buy a dozen.”
What would you bring home?
What do you think the coder brought home?
SCENARIO #1
Upon arrival, his partner angrily asks him, "Why
did you get 12 bottles of milk?" The programmer
says, "There were eggs!"
This is an example of why we don’t program computers with
plain spoken language – we need to formalise the instructions
we give to computers
SCENARIO #1
SCENARIO #2
1 + 2 x 3 + 4
The answer is 11. Mathematics is a much stricter
“language” than spoken English. There are rules
about how things happen. In that way, coding is
a lot of maths.
SCENARIO #3
How do you make toast?
‘How do you make toast?’ is an interview question for software
developers, because it reveals whether you think computationally.
The ideal answer is a couple of steps away from something a robot
could understand. For a robot, clarity and precision are everything.
“Take four steps forward, open packet of bread, remove one slice
of bread”, for example, is a better start than “put bread in toaster”.
WHAT ARE ALGORITHMS?
• An algorithm is basically a set of step by step
instructions
• Before writing any code, you need to start with an
algorithm
• We need to determine what we're trying to achieve,
and then break down the problem into step by step
instructions.
• Once we have an algorithm, we can write code to
make a program
THE RULES FOR ALGORITHMS
• precisely states a set of instructions
• the procedure always finishes
• and it can be proven that it works in all cases
HOW TO SOLVE A PROBLEM
• When you use your brain to take a big problem and break it
down into smaller problems, you’re using your brain to
decompose the big problem.
• Once we’ve decomposed the big problem into several smaller
problems, we can go onto our next trick, which is called
pattern match. This is when we look for similarities.
• Once I find the things that are the same, I can figure out what
things are different. And when I remove those differences,
that’s called abstraction.
• And after I’ve figured out the steps to solving a problem, I can
put those steps in a specific order called an algorithm, so that
anyone can use my directions to solve that problem.
THE CHILLI GAME
• Put 13 Chocolates in a bowl
• Put 1 Chilli in a bowl
• Whoever brought the chocolates goes first
• You can take 1, 2 or 3 chocolates at a time
• The aim is not to be left with the chilli
Instructions
THE CHILLI GAME
• 13 chocolates divides into three groups of 4, with
one left over
• I take one in the first round, leaving 12
• Then I take 4 minus whatever you took in the
subsequent round,
• This algorithm ensures that the other player is always
left with the chilli
How the algorithm works:
THE CHILLI GAME - ALGORITHM
• I take 1 chocolate
• You take 1, 2 or 3 chocolates (x1)
• I take (4 - x1)
• You take 1, 2 or 3 chocolates (x2)
• I take (4 - x2)
• You take 1, 2 or 3 chocolates (x3)
• I take (4 - x3)
• You take the chilli 
HERE’S ANOTHER MATHS PROBLEM
Add all the numbers from 1 to 200 in your head.
You’ve got 30 seconds!
1 + 2 + 3 + ... + 198 + 199 + 200
1 + 200 = 201
2 + 199 = 201
3 + 198 = 201
201 x 100 = 20,100
MATH PROBLEM – ALGORITHM 1
• TOTAL = 0
• NUMBER = 0
• START
• Increase NUMBER by 1
• Add NUMBER to TOTAL
• If (NUMBER < 200) Go back to START
This algorithm is inefficient
MATH PROBLEM – ALGORITHM 2
• STARTNUM = 1
• ENDNUM = 200
• TOTAL = 0
• If (ENDNUM is odd) add ENDNUM to TOTAL
• If (ENDNUM is odd) subtract 1 from ENDNUM
• TOTAL = TOTAL +
(ENDNUM / 2) * (STARTNUM + ENDNUM)
This algorithm is efficient, because the number
of instructions don’t increase with the size of
ENDNUM
SORTING ALGORITHMS
Bubble Sort:
Sort these numbers: 5, 4, 2, 1, 3
SORTING ALGORITHMS
Merge Sort
Sort these numbers: 5, 2, 4, 6, 1, 3, 2, 6
THE STABLE MARRIAGE ALGORITHM
In 2012, for the first time, a nobel prize was
awarded because of an algorithm.
The algorithm was concerned with college
admissions – how to match students to colleges
so that everyone got a place, but most
importantly, so that everyone was happy, even if
they didn’t get their first choice.
They called it The Stable Marriage Problem…
This is an unstable marriage
Queen of Hearts would prefer King of Spades
King of Spades would prefer Queen of Hearts
+
+
THE STABLE MARRIAGE ALGORITHM
The Gale Shapley algorithm is now used all over the
world:
• In Denmark to match children to daycare places
• In Hungary to match students to schools
• In New York to allocate Rabbis to synagogues
• In China, Germany and Spain to match students to
university places
• In UK it’s lead to the development of a matching
algorithm for organ transplants
GOOGLE PAGERANK ALGORITHM
Not a search algorithm, but a ranking algorithm – ranks
all search results for your query so the #1 is the one
your most likely interested in.
PageRank looks at 2 things:
• The incoming links to a webpage, and
• How important those pages are
GOOGLE PAGERANK ALGORITHM
THE TRAVELLING SALESMAN PROBLEM
A travelling salesman travels door to door
through a number of towns and cities. The
problem – what’s the shortest route to take?
The answer to this problem is so important that
there is a $1 million reward for anyone who can
produce an efficient algorithm, or prove that
none exists…
THE TRAVELLING SALESMAN PROBLEM
Imagine you’re a travelling salesman, and you
need to visit a list of cities. The challenge is to
find the shortest route so you visit each city
once, before returning to your starting point.
You might imagine the best thing is to just
consider all the possible routes..? The method of
checking all the possibilities is a type of
algorithm, but is it efficient?
THE TRAVELLING SALESMAN PROBLEM
• For 3 cities, it works fine because there are
only 3 possible routes to check
• For 5 cities, there are 60 possible routes
• For 6 cities, there are 360 possible routes
• For 10 cities, there are over 1.8 million
possible routes. If a computer calculated 10
routes per second, it would take 2 days before
it found the shortest.
LOGIC STRUCTURES
• IF ( statement ) THEN ( action )
• IF ( statement ) THEN ( action ) ELSE ( action )
• WHILE ( statement ) THEN ( action )
• FUNCTION ( group of actions )
GROUP ACTIVITY #1
Write an algorithm for one of the following:
• The Nutbush
• The Macarena
• The Hokey Pokey
• The Chicken Dance
GROUP ACTIVITY #2
Write an algorithm for making a paper plane.
Then swap with another group and see if they
can follow your instructions.
GROUP ACTIVITY #3
Write an algorithm for a driverless car
approaching an intersection:
• What road rules come into play?
• What should the vehicle be on the lookout
for?
• What actions should the vehicle take?

Mais conteúdo relacionado

Semelhante a Learn to Think Like a Coder

3 solving problems
3 solving problems3 solving problems
3 solving problems
hccit
 

Semelhante a Learn to Think Like a Coder (20)

computational_thinking_gcse.pptx
computational_thinking_gcse.pptxcomputational_thinking_gcse.pptx
computational_thinking_gcse.pptx
 
GRADE 6 ALGORITHM.pptx
GRADE 6 ALGORITHM.pptxGRADE 6 ALGORITHM.pptx
GRADE 6 ALGORITHM.pptx
 
20180324 zen and the art of programming
20180324 zen and the art of programming20180324 zen and the art of programming
20180324 zen and the art of programming
 
3 solving problems
3 solving problems3 solving problems
3 solving problems
 
Testing for everyone agile yorkshire
Testing for everyone agile yorkshireTesting for everyone agile yorkshire
Testing for everyone agile yorkshire
 
What is an algorithm?
What is an algorithm?What is an algorithm?
What is an algorithm?
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Application of algorithm in real life
Application of algorithm in real lifeApplication of algorithm in real life
Application of algorithm in real life
 
Writing algorithms
Writing algorithmsWriting algorithms
Writing algorithms
 
Software Development is Upside Down
Software Development is Upside DownSoftware Development is Upside Down
Software Development is Upside Down
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Counting and Sequences
Counting and SequencesCounting and Sequences
Counting and Sequences
 
Problem Solving (Lecture)
Problem Solving (Lecture)Problem Solving (Lecture)
Problem Solving (Lecture)
 
Machine Learning for Designers - UX Camp Switzerland
Machine Learning for Designers - UX Camp SwitzerlandMachine Learning for Designers - UX Camp Switzerland
Machine Learning for Designers - UX Camp Switzerland
 
AS computing
AS computingAS computing
AS computing
 
Prompt-Engineering-Lecture-Elvis learn prompt engineering
Prompt-Engineering-Lecture-Elvis learn prompt engineeringPrompt-Engineering-Lecture-Elvis learn prompt engineering
Prompt-Engineering-Lecture-Elvis learn prompt engineering
 
Machine Learning for Designers
Machine Learning for DesignersMachine Learning for Designers
Machine Learning for Designers
 
Greedy algorithm for design and analysis
Greedy algorithm for design and analysisGreedy algorithm for design and analysis
Greedy algorithm for design and analysis
 
DutchMLSchool. Introduction to Machine Learning with the BigML Platform
DutchMLSchool. Introduction to Machine Learning with the BigML PlatformDutchMLSchool. Introduction to Machine Learning with the BigML Platform
DutchMLSchool. Introduction to Machine Learning with the BigML Platform
 
Machine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfMachine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConf
 

Mais de Andrew Marks

Mais de Andrew Marks (12)

Wordpress for Business
Wordpress for BusinessWordpress for Business
Wordpress for Business
 
Google Analytics Essential Training
Google Analytics Essential TrainingGoogle Analytics Essential Training
Google Analytics Essential Training
 
A Guide to Google My Business
A Guide to Google My BusinessA Guide to Google My Business
A Guide to Google My Business
 
How WordPress Sites Get Hacked
How WordPress Sites Get HackedHow WordPress Sites Get Hacked
How WordPress Sites Get Hacked
 
An Introduction to Gutenberg, WordPress's New Editor
An Introduction to Gutenberg, WordPress's New EditorAn Introduction to Gutenberg, WordPress's New Editor
An Introduction to Gutenberg, WordPress's New Editor
 
An Introduction to WordPress Hooks
An Introduction to WordPress HooksAn Introduction to WordPress Hooks
An Introduction to WordPress Hooks
 
Processing Client Payments from your WordPress Website
Processing Client Payments from your WordPress WebsiteProcessing Client Payments from your WordPress Website
Processing Client Payments from your WordPress Website
 
GDPR - What You Need To Know
GDPR - What You Need To KnowGDPR - What You Need To Know
GDPR - What You Need To Know
 
10 Tips for Optimising WordPress
10 Tips for Optimising WordPress10 Tips for Optimising WordPress
10 Tips for Optimising WordPress
 
An (Updated) Introduction to Gutenberg
An (Updated) Introduction to GutenbergAn (Updated) Introduction to Gutenberg
An (Updated) Introduction to Gutenberg
 
Ultimate Guide to WordPress Multisite
Ultimate Guide to WordPress MultisiteUltimate Guide to WordPress Multisite
Ultimate Guide to WordPress Multisite
 
Ultimate Guide to Advanced Custom Fields
Ultimate Guide to Advanced Custom FieldsUltimate Guide to Advanced Custom Fields
Ultimate Guide to Advanced Custom Fields
 

Último

哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
ydyuyu
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
F
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Monica Sydney
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 

Último (20)

哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 

Learn to Think Like a Coder

  • 1. Learn to Think Like A Coder Andrew Marks @entreprenerds
  • 2. “Everybody should learn how to program a computer because it teaches you how to think.” - Steve Jobs
  • 3. Six Reasons a Non-Computer Nerd Might Want to Learn to Code 1. It's like learning to read or write 2. It's useful, even outside of computer geek circles 3. It's helps you talk to actual programmers 4. It's actually a fun hobby 5. Computers are a part of society 6. It teaches other skills
  • 4. A coder is going to the grocery store and his partner asks him, “Would you buy a bottle of milk, and if there are eggs, buy a dozen.” What would you bring home? What do you think the coder brought home? SCENARIO #1
  • 5. Upon arrival, his partner angrily asks him, "Why did you get 12 bottles of milk?" The programmer says, "There were eggs!" This is an example of why we don’t program computers with plain spoken language – we need to formalise the instructions we give to computers SCENARIO #1
  • 6. SCENARIO #2 1 + 2 x 3 + 4 The answer is 11. Mathematics is a much stricter “language” than spoken English. There are rules about how things happen. In that way, coding is a lot of maths.
  • 7. SCENARIO #3 How do you make toast? ‘How do you make toast?’ is an interview question for software developers, because it reveals whether you think computationally. The ideal answer is a couple of steps away from something a robot could understand. For a robot, clarity and precision are everything. “Take four steps forward, open packet of bread, remove one slice of bread”, for example, is a better start than “put bread in toaster”.
  • 8. WHAT ARE ALGORITHMS? • An algorithm is basically a set of step by step instructions • Before writing any code, you need to start with an algorithm • We need to determine what we're trying to achieve, and then break down the problem into step by step instructions. • Once we have an algorithm, we can write code to make a program
  • 9. THE RULES FOR ALGORITHMS • precisely states a set of instructions • the procedure always finishes • and it can be proven that it works in all cases
  • 10. HOW TO SOLVE A PROBLEM • When you use your brain to take a big problem and break it down into smaller problems, you’re using your brain to decompose the big problem. • Once we’ve decomposed the big problem into several smaller problems, we can go onto our next trick, which is called pattern match. This is when we look for similarities. • Once I find the things that are the same, I can figure out what things are different. And when I remove those differences, that’s called abstraction. • And after I’ve figured out the steps to solving a problem, I can put those steps in a specific order called an algorithm, so that anyone can use my directions to solve that problem.
  • 11. THE CHILLI GAME • Put 13 Chocolates in a bowl • Put 1 Chilli in a bowl • Whoever brought the chocolates goes first • You can take 1, 2 or 3 chocolates at a time • The aim is not to be left with the chilli Instructions
  • 12. THE CHILLI GAME • 13 chocolates divides into three groups of 4, with one left over • I take one in the first round, leaving 12 • Then I take 4 minus whatever you took in the subsequent round, • This algorithm ensures that the other player is always left with the chilli How the algorithm works:
  • 13. THE CHILLI GAME - ALGORITHM • I take 1 chocolate • You take 1, 2 or 3 chocolates (x1) • I take (4 - x1) • You take 1, 2 or 3 chocolates (x2) • I take (4 - x2) • You take 1, 2 or 3 chocolates (x3) • I take (4 - x3) • You take the chilli 
  • 14. HERE’S ANOTHER MATHS PROBLEM Add all the numbers from 1 to 200 in your head. You’ve got 30 seconds! 1 + 2 + 3 + ... + 198 + 199 + 200 1 + 200 = 201 2 + 199 = 201 3 + 198 = 201 201 x 100 = 20,100
  • 15. MATH PROBLEM – ALGORITHM 1 • TOTAL = 0 • NUMBER = 0 • START • Increase NUMBER by 1 • Add NUMBER to TOTAL • If (NUMBER < 200) Go back to START This algorithm is inefficient
  • 16. MATH PROBLEM – ALGORITHM 2 • STARTNUM = 1 • ENDNUM = 200 • TOTAL = 0 • If (ENDNUM is odd) add ENDNUM to TOTAL • If (ENDNUM is odd) subtract 1 from ENDNUM • TOTAL = TOTAL + (ENDNUM / 2) * (STARTNUM + ENDNUM) This algorithm is efficient, because the number of instructions don’t increase with the size of ENDNUM
  • 17. SORTING ALGORITHMS Bubble Sort: Sort these numbers: 5, 4, 2, 1, 3
  • 18. SORTING ALGORITHMS Merge Sort Sort these numbers: 5, 2, 4, 6, 1, 3, 2, 6
  • 19. THE STABLE MARRIAGE ALGORITHM In 2012, for the first time, a nobel prize was awarded because of an algorithm. The algorithm was concerned with college admissions – how to match students to colleges so that everyone got a place, but most importantly, so that everyone was happy, even if they didn’t get their first choice. They called it The Stable Marriage Problem…
  • 20.
  • 21. This is an unstable marriage Queen of Hearts would prefer King of Spades King of Spades would prefer Queen of Hearts + +
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. THE STABLE MARRIAGE ALGORITHM The Gale Shapley algorithm is now used all over the world: • In Denmark to match children to daycare places • In Hungary to match students to schools • In New York to allocate Rabbis to synagogues • In China, Germany and Spain to match students to university places • In UK it’s lead to the development of a matching algorithm for organ transplants
  • 27. GOOGLE PAGERANK ALGORITHM Not a search algorithm, but a ranking algorithm – ranks all search results for your query so the #1 is the one your most likely interested in. PageRank looks at 2 things: • The incoming links to a webpage, and • How important those pages are
  • 29. THE TRAVELLING SALESMAN PROBLEM A travelling salesman travels door to door through a number of towns and cities. The problem – what’s the shortest route to take? The answer to this problem is so important that there is a $1 million reward for anyone who can produce an efficient algorithm, or prove that none exists…
  • 30. THE TRAVELLING SALESMAN PROBLEM Imagine you’re a travelling salesman, and you need to visit a list of cities. The challenge is to find the shortest route so you visit each city once, before returning to your starting point. You might imagine the best thing is to just consider all the possible routes..? The method of checking all the possibilities is a type of algorithm, but is it efficient?
  • 31. THE TRAVELLING SALESMAN PROBLEM • For 3 cities, it works fine because there are only 3 possible routes to check • For 5 cities, there are 60 possible routes • For 6 cities, there are 360 possible routes • For 10 cities, there are over 1.8 million possible routes. If a computer calculated 10 routes per second, it would take 2 days before it found the shortest.
  • 32. LOGIC STRUCTURES • IF ( statement ) THEN ( action ) • IF ( statement ) THEN ( action ) ELSE ( action ) • WHILE ( statement ) THEN ( action ) • FUNCTION ( group of actions )
  • 33. GROUP ACTIVITY #1 Write an algorithm for one of the following: • The Nutbush • The Macarena • The Hokey Pokey • The Chicken Dance
  • 34. GROUP ACTIVITY #2 Write an algorithm for making a paper plane. Then swap with another group and see if they can follow your instructions.
  • 35. GROUP ACTIVITY #3 Write an algorithm for a driverless car approaching an intersection: • What road rules come into play? • What should the vehicle be on the lookout for? • What actions should the vehicle take?