All language subtitles for 21. Efficient Calculation Example - Solution

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
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
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,980 --> 00:00:07,760 All right, who will come back, so this exercise is very interesting. 2 00:00:07,790 --> 00:00:16,460 This exercise is regarding the calculation of what the calculation of getting, first of all, sand 3 00:00:16,460 --> 00:00:24,410 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 4 00:00:24,410 --> 00:00:28,940 the power of six and finally X in the power of eight. 5 00:00:29,510 --> 00:00:29,720 Right. 6 00:00:29,810 --> 00:00:31,880 So something like that. 7 00:00:32,330 --> 00:00:36,090 And the main question is how should we do it? 8 00:00:36,470 --> 00:00:43,370 So first of all, let's just use something that we know for sure that we have to do is just to create 9 00:00:43,370 --> 00:00:53,000 X and also to read this value from the users or print F, answer X and the user is going to insert the 10 00:00:53,000 --> 00:01:00,400 value of X and we are going to read it using this kind of function to store it inside of variable X. 11 00:01:00,560 --> 00:01:00,890 Right. 12 00:01:01,790 --> 00:01:02,230 Right. 13 00:01:02,510 --> 00:01:11,810 So now that we know about it, let's also create two additional variables or basically let's create 14 00:01:11,810 --> 00:01:12,200 all of them. 15 00:01:12,230 --> 00:01:21,560 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, 16 00:01:21,630 --> 00:01:25,640 then the result is probably also going to be of an integer type. 17 00:01:25,650 --> 00:01:34,730 So int let's say it takes two weeks for X six and X, let's say X six eight. 18 00:01:35,300 --> 00:01:43,160 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 19 00:01:43,160 --> 00:01:44,690 in the power of eight. 20 00:01:45,560 --> 00:01:53,630 So while that's great, OK, we created it and we know that just by making some general understanding 21 00:01:53,630 --> 00:01:59,690 from math, we know that X in the power of two simply equals two X multiplied by X. 22 00:01:59,910 --> 00:02:01,430 OK, nothing complicated. 23 00:02:02,810 --> 00:02:06,260 And we can go and simply use it like this. 24 00:02:06,260 --> 00:02:10,670 So it's in the power of two equals X multiplied by X. 25 00:02:11,420 --> 00:02:14,960 And the question is what is the X in the power of four. 26 00:02:15,080 --> 00:02:17,000 So also very simple. 27 00:02:17,000 --> 00:02:21,320 X multiplied by X, multiplied by X and multiplied by X. 28 00:02:21,500 --> 00:02:25,040 Once again that's X in the power of four. 29 00:02:25,040 --> 00:02:30,980 So X four equals two X multiplied by X, multiplied by X multiplied by X. 30 00:02:32,240 --> 00:02:33,210 That's how you do it. 31 00:02:33,670 --> 00:02:40,940 Similarly, again, the same approach, you simply calculate the X in the power of six and X in the 32 00:02:40,940 --> 00:02:42,040 power of eight. 33 00:02:42,050 --> 00:02:44,000 So let's just write it down. 34 00:02:45,590 --> 00:02:51,410 So X six, six, eight and you simply take it and multiplied. 35 00:02:51,650 --> 00:02:52,790 How many times. 36 00:02:53,600 --> 00:02:56,480 Let's use X, X, X and X. 37 00:02:56,480 --> 00:02:56,930 Right. 38 00:02:57,260 --> 00:03:00,590 Six times and here eight times. 39 00:03:00,600 --> 00:03:06,090 So it will be something like that here. 40 00:03:06,140 --> 00:03:07,940 And I think we are ready to go. 41 00:03:07,970 --> 00:03:15,870 We can also use the print off-line, so print F and let's say X in the power of two equals two percentage. 42 00:03:15,890 --> 00:03:24,380 The X in the power of let's just use here backslash X in the power of four equals two percentage. 43 00:03:24,380 --> 00:03:29,090 The biggest X in the power. 44 00:03:30,230 --> 00:03:33,680 The power of six equals two percentage. 45 00:03:34,250 --> 00:03:44,060 And finally, finally X in the power of eight will be equal to percentage the text and ABN. 46 00:03:44,390 --> 00:03:50,870 And of course now we are going simply to use X do X for X six and eight. 47 00:03:51,050 --> 00:03:56,540 OK, so it seems that everything was done correctly, right. 48 00:03:56,630 --> 00:03:58,460 Everything seems to be working correctly. 49 00:03:59,750 --> 00:04:05,810 And the main question, what will be if we build and run it, so will the result be good. 50 00:04:05,820 --> 00:04:07,190 So let's give it a try so. 51 00:04:07,190 --> 00:04:11,240 And thirty three so we know X is power of two is nine. 52 00:04:11,510 --> 00:04:12,920 Eighty one ok. 53 00:04:12,920 --> 00:04:14,450 Seems to be OK. 54 00:04:14,450 --> 00:04:19,600 Let's just use it with two O K for sixteen sixty four. 55 00:04:19,610 --> 00:04:26,930 OK, so everything seems to be working correctly and this was actually a good solution. 56 00:04:27,230 --> 00:04:35,000 The solution works, but the problem is that this solution is not optimized and it's not the best idea 57 00:04:35,000 --> 00:04:36,650 and the best way that you can solve it. 58 00:04:37,490 --> 00:04:46,370 And the reason for that is very simple because you see guys, the multiplication operation in our computers, 59 00:04:47,090 --> 00:04:54,350 our computers are basically saying the multiplication operations for the computers are a kind of a little 60 00:04:54,350 --> 00:04:56,070 bit heavy operations. 61 00:04:56,090 --> 00:04:59,870 That's how they are considerate of me and they are computational. 62 00:04:59,940 --> 00:05:07,500 Time is a little bit more than just usually using some additional operation, for example, or something 63 00:05:07,500 --> 00:05:07,970 like that. 64 00:05:08,520 --> 00:05:14,820 So my suggestion is if you want to make this program as efficient as possible. 65 00:05:15,240 --> 00:05:20,520 So first of all, what do you have to do is to understand that let's take a look at this exercise and 66 00:05:20,520 --> 00:05:26,390 try to minimize the number of times that we are going to use the multiplication operation. 67 00:05:26,850 --> 00:05:31,810 So if we know, OK, maybe we can use some rules just to minimize it. 68 00:05:32,100 --> 00:05:38,580 So basically, if we know that exceed the power of two is by default, is going to be X multiplied by 69 00:05:38,580 --> 00:05:39,000 X. 70 00:05:39,600 --> 00:05:47,160 But if we know that X in the power of four is X multiplied by X, multiplied by X, multiplied by X, 71 00:05:47,370 --> 00:05:53,790 maybe we can use some mathematical operation and based on the previous result to calculate it here, 72 00:05:53,790 --> 00:05:59,190 instead of using three multiplication operations, use just one. 73 00:05:59,880 --> 00:06:01,350 So what do I mean by that? 74 00:06:02,400 --> 00:06:10,860 I simply mean that we can take instead of X, we can take in the power of two and multiplied by X in 75 00:06:10,860 --> 00:06:11,820 the power of two. 76 00:06:11,850 --> 00:06:12,220 Right. 77 00:06:12,570 --> 00:06:18,860 This will give us X in the power of four, which is basically the mathematical operations for powers. 78 00:06:19,650 --> 00:06:28,680 So when we have some X in the power of two and multiplied by X in the power of two, we simply sum up 79 00:06:28,700 --> 00:06:31,680 the powers two plus two, which is four. 80 00:06:32,520 --> 00:06:40,650 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 81 00:06:40,650 --> 00:06:45,330 we already calculated, and there is no need to calculate it over again. 82 00:06:45,720 --> 00:06:51,900 And multiplied by X in the power of two that will give us X in the power of six and the same can be 83 00:06:51,900 --> 00:06:52,530 done here. 84 00:06:52,530 --> 00:06:57,540 X in the power of four, multiplied by X in the power of four. 85 00:06:58,830 --> 00:07:00,520 So that's how you should approach it. 86 00:07:00,990 --> 00:07:06,900 So you see, instead of using here three multiplications, we used one. 87 00:07:07,140 --> 00:07:11,650 And instead of using here what is five multiplication operation. 88 00:07:11,670 --> 00:07:12,630 We used one. 89 00:07:12,990 --> 00:07:16,080 And also here instead of how is it says how much. 90 00:07:16,080 --> 00:07:18,270 Seven seven multiplication. 91 00:07:18,270 --> 00:07:19,660 We use just one. 92 00:07:20,040 --> 00:07:27,790 So basically we made our program much more efficient and optimized to make these calculations. 93 00:07:28,050 --> 00:07:31,770 So now what we simply have to do is just keep updated. 94 00:07:31,800 --> 00:07:35,620 So it's two multiplied by X2 and the same here. 95 00:07:35,640 --> 00:07:42,860 So it will be X four multiplied by X2 and finally X four multiplied by X four. 96 00:07:44,130 --> 00:07:51,750 And that's how you find these calculations much more efficient because not on every line. 97 00:07:51,750 --> 00:07:57,600 You have to calculate all of these steps that were previously X multiplied, Waksman and so on. 98 00:07:58,020 --> 00:08:01,170 You will see that the result is going to be the same. 99 00:08:01,470 --> 00:08:08,070 OK, so here you have nine, you have X in the power of two to eighty one. 100 00:08:08,610 --> 00:08:10,070 So that seems OK. 101 00:08:10,080 --> 00:08:11,460 So let's take five. 102 00:08:11,880 --> 00:08:12,540 Twenty five. 103 00:08:12,540 --> 00:08:12,780 Six. 104 00:08:12,780 --> 00:08:13,300 Twenty five. 105 00:08:13,920 --> 00:08:14,550 Awesome. 106 00:08:14,730 --> 00:08:15,360 Right guys. 107 00:08:15,380 --> 00:08:17,280 Everything seems to be working correctly. 108 00:08:18,250 --> 00:08:25,090 So I hope this lesson taught you something very important and that the efficiency of your code, efficiency 109 00:08:25,090 --> 00:08:32,470 of what you are doing, how you're making the calculations also based on the logic and then based on 110 00:08:32,470 --> 00:08:38,620 the request and on what you have to calculate, how you take it and make it more efficient, make it 111 00:08:38,620 --> 00:08:41,730 more faster, more accurate and not accurate. 112 00:08:41,920 --> 00:08:44,280 The result is the same, but more efficient. 113 00:08:45,010 --> 00:08:52,270 So efficiency is actually a very important and it's actually the core of one of the core concepts of 114 00:08:52,270 --> 00:08:52,990 programming. 115 00:08:54,070 --> 00:09:02,680 And hopefully when you will make different various complicated programs, you will remember the concept 116 00:09:02,680 --> 00:09:08,770 of efficiency and complexity and maybe you will talk about it also in additional courses. 117 00:09:08,770 --> 00:09:11,580 But until then, thank you so much for watching. 118 00:09:11,590 --> 00:09:13,340 Let me know if you have any questions. 119 00:09:13,370 --> 00:09:19,300 Leave some reviews and feedback so that I will know that these exercises were good for you and you liked 120 00:09:19,300 --> 00:09:20,470 them and use them. 121 00:09:21,020 --> 00:09:26,590 And until the next video, I wish you, as always, a great day. 122 00:09:26,720 --> 00:09:27,520 Great week. 123 00:09:28,000 --> 00:09:28,990 And I'll see you then. 124 00:09:29,170 --> 00:09:29,680 Bye. 11756

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