WEBVTT

00:00.650 --> 00:04.010
In order to solve the problems we're going to come across.

00:04.010 --> 00:11.330
We need to come up with a language or writing algorithm as a way to write down or algorithms so it's

00:11.330 --> 00:14.890
logical and easy to follow.

00:14.890 --> 00:21.370
Last time I said we should first write her algorithms in a way that's easy for us humans to understand

00:22.210 --> 00:29.710
and we could write them in English or whatever language is easiest for you and we will do this in some

00:29.710 --> 00:30.680
parts.

00:30.730 --> 00:37.630
But I want to start transitioning into a real computer language and get used to how it will really work.

00:38.550 --> 00:45.630
We're going to go through some problems and examples and come up with the constructs we'll need for

00:45.630 --> 00:49.380
our algorithms language.

00:49.390 --> 00:52.200
So here's our first problem.

00:52.240 --> 01:01.180
It says writing algorithm that gets Celsius value from the user and outputs that Celsius value in Fahrenheit.

01:01.600 --> 01:08.080
So like I said before the first thing we need to do is understand the problem.

01:08.150 --> 01:12.900
So the first thing it says is get the Celsius value.

01:12.950 --> 01:19.190
So we need some kind of way to get things from the user.

01:19.190 --> 01:27.810
So our very first part of the algorithm will be it's going to say we're just going to start in English

01:27.810 --> 01:35.970
here and get the Celsius.

01:36.130 --> 01:36.810
Now you

01:40.500 --> 01:44.940
user.

01:45.060 --> 01:47.360
So that's the very first thing we should do.

01:48.290 --> 01:56.540
Now a bit more subtly We need to somehow save that Celsius value so we can actually use it.

01:57.050 --> 02:01.270
So to say store

02:04.530 --> 02:05.820
Celsius

02:08.100 --> 02:12.260
now you in two

02:16.740 --> 02:23.800
and sign it two values see.

02:23.820 --> 02:33.570
So we need some kind of way of both naming our values and giving them some and giving them value.

02:33.880 --> 02:41.650
So that's what the sign is it gives it the value and sees just the name of our value that we're going

02:41.650 --> 02:43.160
to use.

02:43.210 --> 02:47.760
This is just like variables in math.

02:48.180 --> 02:50.760
Let's say so.

02:51.160 --> 02:59.420
Next we need to calculate the Fahrenheit value as we know we know see now we have it.

02:59.810 --> 03:09.820
So we need to actually do the calculation so we know that see times 9

03:13.610 --> 03:26.630
over 5 plus 32 will give us the Fahrenheit that.

03:26.700 --> 03:36.110
So now we know that we need some kind of semblance of doing arithmetic operations like multiply divide

03:37.690 --> 03:41.360
addition and subtraction.

03:41.430 --> 03:47.980
So the next thing we need to do is sign store

03:52.580 --> 03:54.590
value from three

03:57.860 --> 04:04.330
step three in which to say the value

04:10.460 --> 04:10.820
right.

04:10.820 --> 04:15.970
So we're kind of doing what we did in step 2 but now we're going to make a new value called afferent

04:15.980 --> 04:18.830
a sign at 3s.

04:19.040 --> 04:24.650
Step three.

04:24.680 --> 04:27.320
So the last thing we'll do is output

04:31.350 --> 04:32.510
Okay.

04:32.630 --> 04:37.460
Now we have to ask yourself does this solve the problem.

04:37.650 --> 04:45.150
So let's go through one more time let's get the Celsius value from user in store that sells its value

04:45.150 --> 04:47.180
and assign it to some value.

04:47.180 --> 04:58.540
See then actually do the calculation and assign and store the value from our previous step into the

04:58.540 --> 04:59.420
value.

05:00.370 --> 05:08.060
And then finally output so does this solve the problem.

05:08.070 --> 05:08.870
I think so.

05:08.880 --> 05:17.150
I think we're I think this works and it's good enough for us to have as an algorithm so we can translate

05:17.150 --> 05:19.850
it to a computer.

05:19.880 --> 05:21.910
So what are the takeaways.

05:23.580 --> 05:31.990
At are needed or that we can add to our language well we need some way

05:35.630 --> 05:38.670
of getting input.

05:38.770 --> 05:40.120
Right now we'll just say

05:43.280 --> 05:52.200
something like get input as our construct number one.

05:52.210 --> 05:55.000
Number two we need some way of

05:58.850 --> 06:05.660
naming and storing values.

06:09.090 --> 06:11.040
That's what we didn't stop to remember.

06:11.040 --> 06:16.920
And step four and we need

06:20.100 --> 06:20.800
arithmetic

06:23.620 --> 06:24.580
expressions

06:27.610 --> 06:29.980
like we did in part 3.

06:31.320 --> 06:33.280
These are just the math symbols

06:37.050 --> 06:43.660
and they'll be a few more that we'll need but for now this is this works.

06:43.690 --> 06:45.130
And lastly we need

06:47.900 --> 06:51.230
some way of outputting

06:54.980 --> 06:56.010
results.

06:57.320 --> 07:05.220
So if you remember in the mental model lecture this works exactly.

07:06.100 --> 07:08.670
The way that I outlined.

07:08.710 --> 07:12.050
So we have the input that's that's one here.

07:12.130 --> 07:28.030
One this this line and then we actually go into the algorithm which is step two step three and step

07:28.030 --> 07:35.820
four and then we have the output which is the last part of our mental model.

07:36.180 --> 07:39.050
So see how this mental model really applies here.

07:43.530 --> 07:46.160
So let's go to a new problem.

07:49.950 --> 07:53.590
So say rates an algorithm

07:56.730 --> 08:06.660
that takes two numbers from the user and outputs the bigger number

08:10.250 --> 08:18.710
so using what we have from one problem one is to

08:24.320 --> 08:26.050
you know how to start.

08:26.070 --> 08:43.230
So get a number from the user an sign that each to call it and one we have to choose that.

08:44.060 --> 08:51.130
And then again get a number from the user and sign it

08:53.790 --> 08:55.760
into.

08:55.770 --> 09:01.280
So those are the first two things we need to numbers so we have going into those numbers.

09:03.230 --> 09:08.410
Now we need some way of comparing two values.

09:08.450 --> 09:22.390
So if you make a comparison between one and 2 let's say we checked this comparison.

09:22.390 --> 09:27.750
This gives you well it's either true or false.

09:27.750 --> 09:29.790
This evaluates either true or false.

09:29.790 --> 09:33.670
Either one is greater than two or it's not.

09:33.690 --> 09:41.100
So this is our very first condition and conditions either evaluate teacher or false.

09:41.100 --> 09:49.680
Like I said just like in math we can we can do this kind of comparison with in this case the greater

09:49.680 --> 09:54.590
than sign is the greater than sign.

09:54.840 --> 10:03.300
Not only that though we need some kind of control flow in this case.

10:03.300 --> 10:16.610
It can either be an one that's bigger than two or it can be in two that's greater than in one in thus

10:16.610 --> 10:19.650
we have two different conditions.

10:19.910 --> 10:26.800
So in this case let's say we have and one is greater than two.

10:26.800 --> 10:30.100
So we would output

10:33.170 --> 10:42.030
and want but there's a different condition that says and 2 is greater than 1 and then we would output

10:44.600 --> 10:53.650
in two so see how we have two different paths of execution.

10:53.650 --> 10:57.700
This is called so or two different cases.

10:57.700 --> 10:58.990
This is case one

11:04.630 --> 11:07.920
and this is case two.

11:10.990 --> 11:13.760
Two.

11:13.960 --> 11:25.840
So we need to somehow have a way of deciding which one it is and how we're going to simplify this is

11:26.340 --> 11:29.560
I'm going to say if

11:32.410 --> 11:42.900
anyone is greater than two then what output and one and this will be all part of the same expression.

11:42.920 --> 11:45.900
So to say otherwise

11:49.080 --> 12:00.110
output into should have then output in one.

12:00.110 --> 12:09.470
So this is one of the tougher things to explain actually actually but just know that there's there's

12:09.470 --> 12:10.910
different paths.

12:11.060 --> 12:17.030
If you have a condition like this this is our condition.

12:19.120 --> 12:23.080
In one it's created into

12:25.650 --> 12:30.440
so that's really it that's our outrage.

12:30.580 --> 12:31.510
So let's see.

12:31.510 --> 12:33.110
Does this work.

12:33.220 --> 12:41.770
So get the number from the user and one and then get another number from the user say and two and then

12:41.770 --> 12:47.650
we'll spell check if and one is greater than and two then output and one.

12:48.010 --> 12:58.480
Otherwise I'll put into this I think solves the problem that is that was asked of us.

12:58.650 --> 13:03.480
So what are the takeaways from here.

13:10.390 --> 13:18.980
So rhenium some conditional

13:21.330 --> 13:29.510
statements that's evaluate to TRUE or FALSE.

13:33.510 --> 13:36.330
That's the condition.

13:36.460 --> 13:42.580
Take away five say take away six.

13:43.280 --> 13:45.590
We need some kind of

13:48.180 --> 13:49.270
control flow

13:52.190 --> 13:55.480
for the different cases.

13:56.390 --> 13:58.040
That we can have

14:00.520 --> 14:08.450
based on condition.

14:08.590 --> 14:14.020
Don't worry too much if you're not completely following this yet we'll be doing a lot of examples.

14:14.030 --> 14:18.740
So you'll you'll get it.

14:18.750 --> 14:22.550
So let's move on to the last problem.

14:22.560 --> 14:27.850
Do this lecture this problem re

14:32.250 --> 14:33.570
consumer space

14:37.510 --> 14:37.890
here.

14:37.900 --> 14:42.010
So given the word

14:47.260 --> 14:48.220
Mississippi

14:58.050 --> 14:59.010
count how many

15:03.100 --> 15:04.520
S's here.

15:07.770 --> 15:08.300
In the word

15:13.170 --> 15:16.540
create algorithm.

15:18.140 --> 15:19.320
So you do.

15:23.900 --> 15:32.380
So of course we know just by looking how many S's there should be it should be only for but that's using

15:32.380 --> 15:40.990
our eyes and computers don't have eyes so we need to somehow have an algorithm that will actually go

15:40.990 --> 15:45.960
through and count how many S's that appear.

15:46.390 --> 15:50.890
So how would we start this well.

15:52.820 --> 15:56.280
We would need some kind of counter to actually count.

15:56.280 --> 16:08.260
So let's say counter jurors see will assign value zero for now.

16:08.350 --> 16:08.750
Right.

16:08.810 --> 16:10.550
Because we started zero.

16:10.790 --> 16:15.340
You don't know how many is here yet.

16:15.420 --> 16:18.680
So counters see assigned to value zero.

16:18.900 --> 16:24.440
So the second step we will start at the beginning

16:30.520 --> 16:39.650
and sign current search letter.

16:39.730 --> 16:48.620
This will be of value to be the first letter in the word.

16:48.760 --> 16:49.100
Right.

16:49.180 --> 16:59.710
So the first letter in the word is M. in we will name the current letter to me.

16:59.730 --> 17:03.480
Let's just call it El.

17:03.510 --> 17:06.140
The first letter is L..

17:09.450 --> 17:14.620
So then we'll have to go through the entire word

17:24.380 --> 17:25.490
in check

17:29.410 --> 17:42.410
if current word or current letter is an --.

17:42.520 --> 17:43.600
Right.

17:43.700 --> 17:49.830
So this is the condition just like we had in problem too.

17:50.250 --> 17:52.030
So we have a condition here.

17:52.350 --> 18:02.800
So if you have a condition then you may have multiple cases so let's just say if current letter

18:06.660 --> 18:07.110
now

18:10.580 --> 18:11.930
is as

18:17.590 --> 18:24.150
then what you should increase the count right.

18:24.210 --> 18:32.090
Crease C by 1 so you add one in as we see in X

18:36.570 --> 18:42.940
and then I guess go to the next letter

18:47.030 --> 18:54.110
and sign it to L. right.

18:54.300 --> 18:57.460
Else you can get the next letter in the word.

18:57.770 --> 18:58.110
So

19:00.810 --> 19:07.240
m so started em good eye or count would not have increased yet.

19:07.560 --> 19:15.790
CS The first asks the count goes to one second as the count goes to season I doesn't count anything

19:15.790 --> 19:16.430
at all.

19:17.300 --> 19:23.850
And then sees an excess of 3 4 and then nothing else right.

19:23.870 --> 19:42.650
Because none of these letters are in S So the takeaway from this is not some kind of way to weigh you

19:44.730 --> 19:54.210
do you know steps multiple times in programming.

19:54.210 --> 19:55.250
Call this a

20:00.820 --> 20:08.690
so we loop through each letter of the word and runs some some steps.

20:08.690 --> 20:16.850
So in this case really the step that we're going to be doing is doing this case in this case doesn't

20:16.850 --> 20:18.080
have an otherwise

20:25.240 --> 20:35.880
there's no otherwise do something we don't really care if it's not an X we just want to keep going.

20:35.880 --> 20:44.410
Great.

20:44.520 --> 20:46.790
That's really all we need for now.

20:49.280 --> 20:57.920
In Don't worry about if you're not really understanding this we'll we'll be going over this a lot and

20:57.920 --> 20:59.650
doing a lot of practice.

20:59.670 --> 21:07.640
So in the next lecture will dive a bit even deeper and really start to formalize this language.

21:07.680 --> 21:09.440
Given the takeaways that you've learned.
