← Back to course
Code Crew G3 / Week 07 / Monday
1/6
Week 07 Β· Algorithms

Monday

// Best way to solve it

Monday: Meet the Idea

Raven has eight number cards. She wants them in order, from smallest to largest.

Rocket tries one plan. Raven tries a different plan. Both plans work, but Raven finishes first. "Your way was faster!" Rocket says. "Teach me!"

Nova glows. "A clear plan is called an algorithm. Some algorithms are faster than others." Let's help them sort some cards.

RAVEN had 8 cards with numbers and wanted them in order, smallest to largest. RAVEN tried two ways. The first way took 30 seconds. The second way took 9 seconds. Both worked. Both are ALGORITHMS, but one is faster.

Big Idea
Many algorithms can solve the same problem.
Faster is usually better, but easier-to-read can win too.
An algorithm is just a clear plan.

What Makes an Algorithm

An algorithm is a clear plan. It has steps in order, and it has an end.

Two people can follow the same algorithm and get the same answer.

SPOT THE ALGORITHM
  • Read the question.
  • Tap your answer.
Which of these is an algorithm?
Raven sorted in 9 seconds. Rocket took 30 seconds. Both worked. Which way was faster?
Sort from smallest to largest: 8, 3, 5. Which number comes first?
What must every algorithm have?
Sort 6, 2, 9, 4 from smallest to largest. Which number is first?
Same numbers. Which number is last?
Same numbers. Which number is second?
StatementTrue or false?
A recipe is a kind of algorithm.?
There is only one algorithm for every problem.?
An algorithm needs steps in order.?
A faster algorithm is always harder to read.?
WHY THIS EXERCISEMany plans can solve a problem. Programmers compare them.
SORT THESE NUMBERS, SMALLEST FIRST
  • ?3
  • ?8
  • ?12
  • ?20
  • ?31
WHY THIS EXERCISESorting is one of the most common jobs computers do.
Raven sorts 4, 1, 3. She picks the smallest card first. Which card does she pick?
WHY THIS EXERCISEPick the smallest is a real sorting algorithm. It repeats until no cards are left.
Try it
Pick five books or toys.
Sort them by size, smallest to biggest.
Say each step of your plan out loud as you go.

Quick Try

Put these cards in order from smallest to largest.

SORT: 7, 2, 9, 1, 5
  • ?7
  • ?9
  • ?2
  • ?1
  • ?5
WHY THIS EXERCISELists like phone contacts, school rosters and game leaderboards are often sorted.