All language subtitles for 21. Efficient Calculation Example - Solution

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

All right, who will come back, so this exercise is very interesting.

This exercise is regarding the calculation of what the calculation of getting, first of all, sand

value, let's say X, and we have to calculate X in the power of two X in the power of four and to extend

the power of six and finally X in the power of eight.

Right.

So something like that.

And the main question is how should we do it?

So first of all, let's just use something that we know for sure that we have to do is just to create

X and also to read this value from the users or print F, answer X and the user is going to insert the

value of X and we are going to read it using this kind of function to store it inside of variable X.

Right.

Right.

So now that we know about it, let's also create two additional variables or basically let's create

all of them.

So if we all know that we multiply X by X plus one time, two times or more R and X is of type integer,

then the result is probably also going to be of an integer type.

So int let's say it takes two weeks for X six and X, let's say X six eight.

OK, so it will correspond to X in the power of to exceed the power of four X in a bowl of six and X

in the power of eight.

So while that's great, OK, we created it and we know that just by making some general understanding

from math, we know that X in the power of two simply equals two X multiplied by X.

OK, nothing complicated.

And we can go and simply use it like this.

So it's in the power of two equals X multiplied by X.

And the question is what is the X in the power of four.

So also very simple.

X multiplied by X, multiplied by X and multiplied by X.

Once again that's X in the power of four.

So X four equals two X multiplied by X, multiplied by X multiplied by X.

That's how you do it.

Similarly, again, the same approach, you simply calculate the X in the power of six and X in the

power of eight.

So let's just write it down.

So X six, six, eight and you simply take it and multiplied.

How many times.

Let's use X, X, X and X.

Right.

Six times and here eight times.

So it will be something like that here.

And I think we are ready to go.

We can also use the print off-line, so print F and let's say X in the power of two equals two percentage.

The X in the power of let's just use here backslash X in the power of four equals two percentage.

The biggest X in the power.

The power of six equals two percentage.

And finally, finally X in the power of eight will be equal to percentage the text and ABN.

And of course now we are going simply to use X do X for X six and eight.

OK, so it seems that everything was done correctly, right.

Everything seems to be working correctly.

And the main question, what will be if we build and run it, so will the result be good.

So let's give it a try so.

And thirty three so we know X is power of two is nine.

Eighty one ok.

Seems to be OK.

Let's just use it with two O K for sixteen sixty four.

OK, so everything seems to be working correctly and this was actually a good solution.

The solution works, but the problem is that this solution is not optimized and it's not the best idea

and the best way that you can solve it.

And the reason for that is very simple because you see guys, the multiplication operation in our computers,

our computers are basically saying the multiplication operations for the computers are a kind of a little

bit heavy operations.

That's how they are considerate of me and they are computational.

Time is a little bit more than just usually using some additional operation, for example, or something

like that.

So my suggestion is if you want to make this program as efficient as possible.

So first of all, what do you have to do is to understand that let's take a look at this exercise and

try to minimize the number of times that we are going to use the multiplication operation.

So if we know, OK, maybe we can use some rules just to minimize it.

So basically, if we know that exceed the power of two is by default, is going to be X multiplied by

X.

But if we know that X in the power of four is X multiplied by X, multiplied by X, multiplied by X,

maybe we can use some mathematical operation and based on the previous result to calculate it here,

instead of using three multiplication operations, use just one.

So what do I mean by that?

I simply mean that we can take instead of X, we can take in the power of two and multiplied by X in

the power of two.

Right.

This will give us X in the power of four, which is basically the mathematical operations for powers.

So when we have some X in the power of two and multiplied by X in the power of two, we simply sum up

the powers two plus two, which is four.

So if we want to do the same also for X in the power of six, we can take X in the power of four, which

we already calculated, and there is no need to calculate it over again.

And multiplied by X in the power of two that will give us X in the power of six and the same can be

done here.

X in the power of four, multiplied by X in the power of four.

So that's how you should approach it.

So you see, instead of using here three multiplications, we used one.

And instead of using here what is five multiplication operation.

We used one.

And also here instead of how is it says how much.

Seven seven multiplication.

We use just one.

So basically we made our program much more efficient and optimized to make these calculations.

So now what we simply have to do is just keep updated.

So it's two multiplied by X2 and the same here.

So it will be X four multiplied by X2 and finally X four multiplied by X four.

And that's how you find these calculations much more efficient because not on every line.

You have to calculate all of these steps that were previously X multiplied, Waksman and so on.

You will see that the result is going to be the same.

OK, so here you have nine, you have X in the power of two to eighty one.

So that seems OK.

So let's take five.

Twenty five.

Six.

Twenty five.

Awesome.

Right guys.

Everything seems to be working correctly.

So I hope this lesson taught you something very important and that the efficiency of your code, efficiency

of what you are doing, how you're making the calculations also based on the logic and then based on

the request and on what you have to calculate, how you take it and make it more efficient, make it

more faster, more accurate and not accurate.

The result is the same, but more efficient.

So efficiency is actually a very important and it's actually the core of one of the core concepts of

programming.

And hopefully when you will make different various complicated programs, you will remember the concept

of efficiency and complexity and maybe you will talk about it also in additional courses.

But until then, thank you so much for watching.

Let me know if you have any questions.

Leave some reviews and feedback so that I will know that these exercises were good for you and you liked

them and use them.

And until the next video, I wish you, as always, a great day.

Great week.

And I'll see you then.

Bye.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.