Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
In this video we're going to do something unusual  we're going to play a game where two of my friends try to guess a number. It's relevant, I promise!

0:00
Hey again.

0:01
In this video we're going to do something unusual.

0:03
We're going to play a game, and by we, I mean me and my two friends here,

0:07
Brittany and John.

0:08
This game is really simple, and you may have played it before.

0:11
It goes something like this, I am going to think of a number between 1 and 10, and

0:15
they have to guess what the number is.

0:17
Easy, right?

0:19
When they guess a number, I'll tell them if their guess is too high or too low.

0:23
The winner is the one with the fewest tries.

0:25
All right, John, let's start with you.

0:27
I'm thinking of a number between 1 and 10, what is it?

0:30
Between you and me, the answer is three.

0:33
>> Quick question, does the range include one and ten?

0:36
>> That is a really good question, and so

0:38
what John did right there was to establish the bounds of our problem.

0:42
No solution works on every problem, and an important part of algorithmic thinking is

0:46
to clearly define what the problem set is and clarify what values count as inputs.

0:51
Yeah, one and ten are both included.

0:54
Is it one?

0:55
>> Too low. >> Is it two?

0:56
>> Too low.

0:56
>> Is it three?

0:57
>> Correct.

0:58
Okay, so that was an easy one.

1:00
It took John three tries to get the answer.

1:03
Let's switch it over to Brittany and

1:04
play another round using the same number as the answer.

1:07
Okay Brittany, I'm thinking of a number between one and ten inclusive, so

1:10
both one and ten are in the range.

1:12
What number am I thinking of?

1:13
>> Is it five?

1:14
>> Too high.

1:15
>> Two?

1:16
>> Too low.

1:16
>> Is it three?

1:17
>> Correct.

1:18
All right, so

1:19
what we had there was two very different ways of playing the same game.

1:24
Somehow, with even such a simple game,

1:26
we saw different approaches to figuring out a solution.

1:29
To go back to algorithmic thinking for

1:31
a second, this means that with any given problem, there's no one best solution.

1:36
Instead what we should try and figure out is what solution works better for

1:40
the current problem.

1:42
In this first pass at the game they both took the same amount of turns

1:46
to find the answer.

1:47
So it's not obvious who has the better approach,

1:49
and that's mostly because the game was easy.

1:52
Let's try this one more time, now this time the answer is ten.

1:56
All right, John, you first.

1:57
>> Is it one?

1:57
>> Too low.

1:58
>> Is it two?

1:59
>> Still too low.

2:00
>> Is it three?

2:00
>> Too low.

2:01
>> Is it four?

2:02
>> Too low.

2:02
>> Is it five?

2:03
>> Still too low.

2:04
>> Is it six?

2:04
>> Too low.

2:05
>> Is it seven?

2:06
>> [LAUGH] Too low.

2:07
>> Is it eight?

2:07
>> [LAUGH] Too low.

2:08
>> Is it nine?

2:09
>> Too low.

2:10
>> Is it ten?

2:10
>> Correct, you got it.

2:12
Okay, so now same thing, but with Brittany this time.

2:15
>> Is it five?

2:17
>> Too low.

2:18
>> Eight? >> Too low.

2:19
>> Is it nine?

2:20
>> Still too low.

2:21
>> It's ten.

2:21
>> All right, so here we start to see a difference between their strategies.

2:26
When the answer was three they both took the same number of turns.

2:29
This is important.

2:31
When the number was larger, but not that much larger, ten in this case,

2:35
we start to see that Brittany's strategy did better.

2:38
She took four tries while John took 10.

2:40
We've played two rounds so far and

2:42
we've seen a different set of results based on the number they were looking for.

2:46
If you look at John's way of doing things, then the answer being ten,

2:49
the round we just played, is his worst case scenario.

2:53
He will take the maximum number of turns, ten, to guess it.

2:56
When we picked a random number like three, it was hard to differentiate which

3:01
strategy was better, because they both performed exactly the same, but

3:06
in John's worst case scenario a clear winner in terms of strategy emerges.

3:10
In terms of algorithmic thinking, we're starting to get a sense that the specific

3:15
value they're searching for may not matter as much as where that value

3:19
lies in the range that they have been given.

3:22
Identifying this helps us understand our problem better.

3:26
Let's do this again for a range of numbers from 1 to 100.

3:29
We'll start by picking five as an answer to trick them.

3:32
Okay, so this time we're going to run through the exercise again, but

3:35
this time from 1 to 100, and both 1 and 100 are included.

3:39
>> Is it one?

3:40
>> At this point without even having to run through it we can guess how many tries

3:43
John is going to take.

3:44
Since he starts at one and

3:45
keeps going he's going to take five tries as we're about to see.

3:48
>> Is it five?

3:49
>> Cool, correct.

3:49
Okay, now for Brittany's turn.

3:51
>> Is it 50?

3:53
>> Too high.

3:54
>> Is it 25?

3:55
>> Still too high.

3:56
>> Is it 13?

3:57
>> Too high.

3:58
>> Is it seven?

3:59
>> Too high.

4:00
>> Is it four?

4:01
>> Too low.

4:02
>> Is it six?

4:03
>> Too high.

4:04
>> Is it five?

4:06
>> Correct.

4:07
Let's evaluate.

4:08
John took five tries, Brittany, on the other hand, took seven tries.

4:12
So John wins this round, but again,

4:14
in determining whose strategy is preferred there is no clear winner right now.

4:18
What this tells us is that it's not particularly useful to look at

4:22
the easy answers where we arrive at the number fairly quickly because it's at

4:26
the start of the range.

4:27
Instead, let's try one where we know John is going to do poorly.

4:31
Let's look at his worse case scenario where the answer is 100 and

4:35
see how Brittany performs in such a scenario.

4:38
Okay, John, let's do this one more time, 1 through 100, again.

4:41
>> Is it one?

4:42
>> We can fastforward this scene because, well, we know what happens.

4:45
John takes 100 tries.

4:47
All right, Brittany, you're up.

4:49
>> Is it 50?

4:50
>> Too low.

4:51
>> Is it 75?

4:52
>> Too low.

4:53
>> 88?

4:53
>> Too low.

4:54
>> 94?

4:55
>> Too low.

4:56
>> Is it 97?

4:57
>> Too low.

4:58
>> 99?

4:59
>> Too low.

5:00
>> 100.

5:02
>> Okay, so that took Brittany seven turns again, and

5:05
this time she is the clear winner.

5:07
If you compare their individual performances for the same number set,

5:11
you'll see that Brittany's approach leaves John's in the dust.

5:14
When the answer was five, so

5:16
right around the start of the range, John took five turns, but

5:19
when the answer was 100, right at the end of the range, he took 100 tries.

5:23
It took him 20 times the amount of tries to get that answer compared to Brittany.

5:28
On the other hand, if you compare Brittany's efforts,

5:31
when the number was five, she took seven tries, but

5:34
when the number was one hundred, she took the same amount of tries.

5:37
This is pretty impressive.

5:38
If we pretend that the number of tries is the number of seconds it takes Brittany

5:43
and John to run through their attempts, this is a good estimate for

5:46
how fast their solutions are.

5:49
Okay, we've done this a couple of times, and Brittany and John are getting tired.

5:52
Let's take a break.

5:53
In the next video we'll talk about the point of this exercise.
You need to sign up for Treehouse in order to download course files.
Sign up