All language subtitles for 22. SUPER EXERCISE Swap O(1) Complexity!

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
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
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:05,400 --> 00:00:11,070 OK, guys, so what I'm going to do now is a little bit tricky, and I want you to pay close attention 2 00:00:11,340 --> 00:00:13,060 to what we are going to do next. 3 00:00:13,590 --> 00:00:20,760 I'm going to create a function that is responsible for generating a dynamically allocated array and 4 00:00:20,790 --> 00:00:23,870 also getting it from the user so it will go like this. 5 00:00:23,880 --> 00:00:32,790 So instar generate generator rate and these are function is going to receive simply the size of the 6 00:00:32,790 --> 00:00:33,090 array. 7 00:00:33,240 --> 00:00:34,130 OK, very simple. 8 00:00:34,650 --> 00:00:41,310 And what we are going to do here is to create a pointer into pointer error and we are going to say that 9 00:00:41,310 --> 00:00:51,870 we are equals to inStar Mallock and basically the same things we've done and used in our previous memory 10 00:00:51,870 --> 00:00:53,360 allocation things and so on. 11 00:00:53,760 --> 00:00:58,980 So endpoints r r r r equals to install Ramallo at it, let's say. 12 00:00:59,310 --> 00:01:01,800 Now we are also going to do something like that. 13 00:01:01,810 --> 00:01:05,230 So receiving the values from the user. 14 00:01:05,260 --> 00:01:12,540 So for I equals to zero, as long as I is less than let's say size. 15 00:01:12,540 --> 00:01:12,990 Right. 16 00:01:12,990 --> 00:01:14,610 And plus, plus that's it. 17 00:01:14,970 --> 00:01:19,830 So as long as that's the case, let's use this kind of function to read the value from the user and 18 00:01:19,830 --> 00:01:21,930 put it inside these allocated arrays. 19 00:01:21,930 --> 00:01:29,340 So percentage D OK and put it inside a rather IT index I write. 20 00:01:29,880 --> 00:01:37,980 So hopefully nothing complicated here and we understand what's happening and we are simply getting the 21 00:01:37,980 --> 00:01:38,890 size of the array. 22 00:01:38,910 --> 00:01:43,940 We want to allocate, we allocate these array of these specified size. 23 00:01:43,950 --> 00:01:51,490 We iterate over all of it and initialize the elements in simply like reading the values from the user. 24 00:01:51,870 --> 00:01:54,570 And finally, we simply return these array. 25 00:01:54,570 --> 00:01:56,180 So return here. 26 00:01:56,520 --> 00:01:57,040 That's it. 27 00:01:57,570 --> 00:02:02,460 So instead of using these two static arrays, what we are going to do is to use some pointers. 28 00:02:02,460 --> 00:02:07,580 So in error one and pointer error to write like that. 29 00:02:08,070 --> 00:02:11,160 So that's what we are going to do. 30 00:02:11,280 --> 00:02:18,090 And now what we are going also to do is call this function error. 31 00:02:18,150 --> 00:02:23,110 One equals to generate array generator rate, let's say is off site. 32 00:02:23,140 --> 00:02:24,600 Let's make it very generic. 33 00:02:24,600 --> 00:02:30,420 Like to use here print f enter a size for array one. 34 00:02:30,600 --> 00:02:35,970 Now we need also to do it for the second size of the arrows, for the size of the second array. 35 00:02:36,240 --> 00:02:41,370 So enter size for Array two and read the value for size array two. 36 00:02:41,760 --> 00:02:42,630 So that's it. 37 00:02:42,900 --> 00:02:48,930 OK, so we got the sizes of the arrays that we want because we don't want to created static as it was 38 00:02:48,930 --> 00:02:49,380 previous. 39 00:02:49,530 --> 00:02:55,830 We want to make it dynamic and to let the user decide what should be the sizes of the arrays as well 40 00:02:55,830 --> 00:03:03,090 as also above them, as well as also what do we want to do, as well as also letting the user the option 41 00:03:03,090 --> 00:03:05,490 to specify the values of the array. 42 00:03:05,730 --> 00:03:10,280 So here are one equals to generate what is a generates array. 43 00:03:10,380 --> 00:03:17,790 And here we are going to specify size of array one and also eight or two equals to generate array and 44 00:03:17,790 --> 00:03:21,540 specify size array to that's it. 45 00:03:22,080 --> 00:03:27,780 So at this point we should already have two eraser error, one year two. 46 00:03:28,140 --> 00:03:36,300 And we are going to do is instead of using this function of swap error and iterate over all the elements, 47 00:03:36,510 --> 00:03:43,040 assuming that both of them are of the same size of Corsia, but instead of iterating over all of the 48 00:03:43,040 --> 00:03:46,200 other elements, we are going to do a little trick here. 49 00:03:46,260 --> 00:03:54,630 And what we are going to do is simply to create additional function and call this function void, void 50 00:03:54,630 --> 00:04:00,500 swap swap array in just one constant operation. 51 00:04:00,510 --> 00:04:03,060 Let's call it swap array, old one. 52 00:04:03,160 --> 00:04:11,010 OK, guys, in what we are going to do in these function is simply to receive OK to receive some values 53 00:04:11,350 --> 00:04:19,660 referred or related to these two arrays and to swap them in just one single swap operation. 54 00:04:20,070 --> 00:04:25,230 So what do I mean by that instead of going and iterating over all the elements? 55 00:04:25,230 --> 00:04:25,470 Right. 56 00:04:25,470 --> 00:04:32,700 We know the address of the first element of in of the first element inside of this array and the first 57 00:04:32,700 --> 00:04:34,060 element inside of that array. 58 00:04:34,320 --> 00:04:38,730 So both of them we have here are one and a are two. 59 00:04:39,000 --> 00:04:40,830 Both of them are simply variables. 60 00:04:40,830 --> 00:04:41,150 Right. 61 00:04:41,160 --> 00:04:43,020 We can see imagine them here. 62 00:04:43,030 --> 00:04:45,870 So variable error, one a year or two. 63 00:04:46,050 --> 00:04:48,540 And both of them are simply pointing to somewhere. 64 00:04:48,540 --> 00:04:52,890 They both hold some address, OK, both of them have some address. 65 00:04:53,640 --> 00:05:00,990 And what we are going to do is simply to let a r r one point from this point on, not the the allocated 66 00:05:00,990 --> 00:05:04,410 array for error one, but to point to. 67 00:05:04,670 --> 00:05:11,990 You are, too, and here are one and two is going to point to the values and the array allocated for 68 00:05:12,020 --> 00:05:13,270 everyone. 69 00:05:14,390 --> 00:05:18,560 So that's not very straightforward, but I think you've got the idea. 70 00:05:18,860 --> 00:05:25,640 So we need to change the value inside of Iraq one and inside of Iraq to buy reference. 71 00:05:25,880 --> 00:05:30,200 So we will send the addresses of these pointers. 72 00:05:30,230 --> 00:05:37,460 Notice not the array themselves, not the address where they point to, but the address of the variables 73 00:05:37,460 --> 00:05:40,100 here are one and area to themselves. 74 00:05:40,130 --> 00:05:42,800 So we are going to send it to these function. 75 00:05:42,800 --> 00:05:45,680 Let's call it a swap ratio of one. 76 00:05:45,890 --> 00:05:50,750 We are going to send the address of Iraq one and the address of a or two. 77 00:05:50,930 --> 00:05:52,490 That's what we are going to do. 78 00:05:52,940 --> 00:05:56,570 And the address of a year or one is going to be received here. 79 00:05:56,630 --> 00:05:58,220 So how should you receive it? 80 00:05:58,400 --> 00:06:07,700 Basically, one way to do so is to get it as something like this and pointer, let's go like a Pityana, 81 00:06:07,730 --> 00:06:10,970 let's call it Padawan and inStar BTR or two. 82 00:06:11,630 --> 00:06:17,870 But in this case, we know that BTR one should point to integer, but we know that error one is not 83 00:06:17,870 --> 00:06:20,540 a simple integer, it's a pointer to integer. 84 00:06:20,540 --> 00:06:27,260 You can see it here then we need that BTR one will be a pointer to a pointer to integer. 85 00:06:27,260 --> 00:06:35,750 So that's why we add additional asterisk here and that's how we point to the through the pointers that 86 00:06:35,750 --> 00:06:41,030 basically point do the arrays allocate it so awesome. 87 00:06:41,030 --> 00:06:47,720 And now what we have to do is simply to use another variable. 88 00:06:47,720 --> 00:06:50,370 So let's use end are a temp, OK? 89 00:06:50,420 --> 00:06:57,590 Because we are using Pointer Atem because temp is going to hold the address of where the array one of 90 00:06:57,620 --> 00:06:59,180 the arrays is going to reside. 91 00:06:59,190 --> 00:07:04,460 So that's why it's of a pointer to int you notice the difference between the original swap. 92 00:07:05,450 --> 00:07:12,590 So Tampoe equals to Peter one and pointer BTR one is simply the value of error. 93 00:07:12,590 --> 00:07:14,510 One, the value of error. 94 00:07:14,510 --> 00:07:19,280 One is the address where the array error one currently resides. 95 00:07:19,490 --> 00:07:22,000 And also we are going to do that for BTR. 96 00:07:22,050 --> 00:07:25,370 Two equals two equals two. 97 00:07:25,370 --> 00:07:28,670 No PDR one equals two points or Peter two. 98 00:07:28,940 --> 00:07:33,560 And finally points are BTR two is going to be equal to temp. 99 00:07:34,400 --> 00:07:36,680 So notice what we've done here. 100 00:07:37,130 --> 00:07:46,280 We simply said that now instead of aira one pointing to the allocated array of error, one error, one 101 00:07:46,280 --> 00:07:52,970 by reference, if we're using these PDR one and Piedra two for our help, he's going to point to the 102 00:07:53,000 --> 00:07:57,180 of the other array and Pertierra two is going to end error. 103 00:07:57,200 --> 00:08:01,190 Two is going to point to error, one to what it was pointing previously. 104 00:08:01,640 --> 00:08:09,500 So that's what we've done behind the scenes, guys, in just one operation without taking into consideration 105 00:08:09,800 --> 00:08:14,150 how and what will be the size of each of these arrays. 106 00:08:14,570 --> 00:08:20,870 And one thing that also can be done here is since we you already know the type and the general type, 107 00:08:21,080 --> 00:08:26,480 instead of using it, we could have just simply used void here because it's a universal type. 108 00:08:26,480 --> 00:08:31,400 We are working just with addresses and we don't really care if it's a point or two points or two. 109 00:08:31,400 --> 00:08:39,350 And it's we can use it just as a universal abstraction, this given function who. 110 00:08:39,350 --> 00:08:41,240 So I hope you got it clear. 111 00:08:41,240 --> 00:08:45,140 Maybe I will add some also visualizations for you to understand this concept. 112 00:08:45,650 --> 00:08:49,010 And basically, if you have any questions, feel free to ask. 113 00:08:49,340 --> 00:08:57,110 We will do our best to respond to your questions on my recommendation is before you jump and move on 114 00:08:57,110 --> 00:09:00,260 and even write this code on your own, write down these function. 11442

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