1. 12:38
Algorithms
Algorithms in Computer Science
What’s covered: 1. What is an Algorithm 2. Algorithms in the real world 3. What makes a good algorithm?
4. Writing your own Algorithm. 5. Evaluating Algorithms. 6. Big picture – interesting discussion question.
Lesson 1
2. 12:38
Definition of an algorithm.
For your notebooks: In essence, algorithms are simply a series of
instructions that are followed, step by step, to do something useful or solve
a problem.
Starter question:
I have a series of facedown cards. One of them is the number “7”. The
cards are organised in ascending order (smallest to biggest).
You can flip one card at a time. What is the quickest way to find number 7?
index numbers
3. 12:38
You have just developed an algorithm!
1. Flip over the first card
2. If it is not 7, then flip over the second card
3. Keep doing this until the number 7 is found!
The above algorithm is essentially a LINEAR SEARCH. It will
work but if no. 7 is at the end, it will take a long time.
Imagine if you had a million cards!
Can you think of a better way? (answer revealed in this series!)
7
7
index numbers
4. 12:38
Why are algorithms important?
• They organize thought and action (computational
thinking)
• They can be made very precise for implementation on
computers, smart phones, and other devices • in a
variety of programming languages (e.g. Python, R,
Java) • as computer programs, software packages,
mobile apps
• A computer program is an implemented algorithm
6. 12:38
Every time you use Google or Facebook
• Every time you hit the
search button on Google,
the search engine sifts
through thousands, if not
millions of webpages, to
spit out the content you
are seeking in a fraction of
a second.
• What makes this possible
is the underlying
algorithm—a simple set of
mathematical rules
embedded in the software.
Facebook and Google search are also
based on algorithms, though they are more
complex than the regular algorithms," he
said.
7. 12:38
Task:
You have been given the task
to program a kid-friendly
robot.
The robot must move around
the room and must ask young
children if they have washed
their hands and encourage
them to do so if they have not. It
must continue to do this until
every pupil in the class has
washed their hands.
Write an algorithm to achieve
this. The robot will follow your
instructions.
1: Take two steps forward.
2: If you collide with a pupil, ask the
pupil for their name …
8. sda
12:38
What makes a good algorithm?
Suggested activity: A few pupils can read out
their algorithm.
Evaluate:
1. What are some good points about their
algorithm?
2. How could they improve it?
9. sda
12:38
What makes a good algorithm?
Correctness: the algorithm performs the task
without error
Efficiency: the algorithm uses as little time and/or
as little space as necessary, but there is almost
always a trade-off between time and space
Comprehensibility: the algorithm can be
understood (which helps with human efficiency)
C
E
C
Can you improve yours?
10. sda
12:38
Interesting reading
Do humans have algorithms?
Underlying that idea is another: that organisms —
including human beings — are essentially algorithmic.
That even the human mind is itself only a super-complex algorithm, and
in order to model it perfectly all we need to do is build our
own algorithm of sufficient sophistication.
Is there more to a human or are we essentially very complex input-
processing-output machines? What do you think?
11. sda
12:38
“Big picture” discussion
Sometimes we hear it said that certain behaviours
are “hard wired” like permanent algorithms into
us. Some people have personalities that are
“angry” and others are always “fearful”.
Are there algorithms at play in our own humanity?
Can we alter these apparent algorithms? How?
Encourage students to think about different algorithms that would be most efficient at retrieving the number 7, if number 7 was the third card or the last card!
The answer is yes!
Image source: preppykitchen.com
The answer is yes!
Image source: preppykitchen.com