All language subtitles for 6. A Program to find if an Array is sorted - 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,630 --> 00:00:04,290 OK, so now let's start solving this exercise. 2 00:00:04,520 --> 00:00:09,720 OK, so basically we will assume that it's used here. 3 00:00:10,770 --> 00:00:11,340 Fine. 4 00:00:11,580 --> 00:00:12,000 I don't know. 5 00:00:12,030 --> 00:00:13,500 Sighs Fight. 6 00:00:14,040 --> 00:00:16,770 OK, and let's create an array of this size. 7 00:00:16,830 --> 00:00:20,130 So age, IRR of size, size. 8 00:00:20,400 --> 00:00:30,960 OK, now we are going also to use this variable that will be used to get inputs from the user into iterate 9 00:00:30,960 --> 00:00:33,150 over all the elements of this array. 10 00:00:33,660 --> 00:00:37,610 So Fawry equals zero iis less than size plus. 11 00:00:37,920 --> 00:00:42,090 And as long as this condition, as long as it is less than size is true. 12 00:00:42,430 --> 00:00:43,470 It is, yes. 13 00:00:44,190 --> 00:00:48,810 Then in this case we are going to print a nice message that is green. 14 00:00:49,350 --> 00:00:51,920 Please answer now. 15 00:00:51,930 --> 00:01:02,010 Element number percentage D and we are going to read this value and to storeyed where are we going to 16 00:01:02,010 --> 00:01:05,670 store it inside of the associated element in these arrays. 17 00:01:05,670 --> 00:01:09,090 Historic inside Iraq index. 18 00:01:10,230 --> 00:01:12,080 OK, is that clear so far? 19 00:01:12,390 --> 00:01:15,910 So that's the operation of just reading the inputs from the user. 20 00:01:15,930 --> 00:01:18,030 So that's related to reading. 21 00:01:18,960 --> 00:01:31,590 Reading includes inputs of reading the values of the elements from the user. 22 00:01:32,220 --> 00:01:33,840 OK, awesome. 23 00:01:34,530 --> 00:01:43,250 Now once you have your array ready on, basically you entered, you got all the elements from the user. 24 00:01:43,300 --> 00:01:50,820 Now it's time to see if the arrays really sorted from the left or the right, sorted or basically not 25 00:01:50,820 --> 00:01:51,690 sorted at all. 26 00:01:53,550 --> 00:01:55,290 What do we have to do here? 27 00:01:55,440 --> 00:01:58,860 What do you think should be what techniques should be applied? 28 00:01:59,190 --> 00:02:01,700 OK, so what do you think, guys? 29 00:02:03,300 --> 00:02:06,280 We have three options, three options here. 30 00:02:06,300 --> 00:02:10,710 So one of these options has finally to be printed out. 31 00:02:10,710 --> 00:02:17,850 So let's say if I don't know, we found out something, then I don't know. 32 00:02:17,850 --> 00:02:26,310 Print half of the array is like really, really sorted. 33 00:02:26,880 --> 00:02:29,310 OK, so that's option number one. 34 00:02:31,080 --> 00:02:37,280 On the other hand, there may be also another option and another option also with some conditions. 35 00:02:37,290 --> 00:02:37,540 Right. 36 00:02:37,560 --> 00:02:40,950 So if and if and if and so on. 37 00:02:41,160 --> 00:02:47,980 OK, so the array is sorted and also the array is not sorted. 38 00:02:48,000 --> 00:02:49,340 OK, so three options. 39 00:02:49,950 --> 00:02:50,820 What do you think? 40 00:02:50,820 --> 00:02:58,080 How should you approach this exercise, how you basically should think about it, how should you solve 41 00:02:58,080 --> 00:03:03,060 it, how should you even find or what is the expected result. 42 00:03:03,180 --> 00:03:03,750 OK, so. 43 00:03:05,100 --> 00:03:12,300 Any ideas and one of the options that you have to understand is that basically what you will have to 44 00:03:12,300 --> 00:03:18,060 do is at least look for are a couple, at least one pair. 45 00:03:18,270 --> 00:03:19,710 OK, one pair. 46 00:03:20,250 --> 00:03:22,790 That does not satisfy the condition here. 47 00:03:22,800 --> 00:03:28,890 So first of all, the condition here, what is the condition is are left element. 48 00:03:29,700 --> 00:03:34,410 All the left elements are less then the right elements. 49 00:03:34,480 --> 00:03:45,090 OK, for any pair that we take Fasal, for any pair, for any pair, the element on the left should 50 00:03:45,090 --> 00:03:47,490 be less than the element on the right. 51 00:03:48,330 --> 00:03:49,890 So that's how it is. 52 00:03:50,010 --> 00:03:58,350 OK, so for any pair that we take in this sequence of elements, all every element on the left should 53 00:03:58,350 --> 00:04:04,260 be less than the element on the right and in this condition is not satisfied that for sure we can see 54 00:04:04,260 --> 00:04:07,180 that the array is not OK. 55 00:04:07,200 --> 00:04:13,110 So if we take also this information for a like this array, OK for the secondary. 56 00:04:13,440 --> 00:04:20,850 So for any pair, the left element should be less than or at least equal to the right element in this 57 00:04:20,850 --> 00:04:21,540 condition. 58 00:04:21,550 --> 00:04:23,880 He's not satisfied, at least for one pair. 59 00:04:24,330 --> 00:04:28,760 Then we can definitely see that the array is not sorted at all. 60 00:04:29,640 --> 00:04:33,510 So let's start and see what we can do with that. 61 00:04:34,020 --> 00:04:39,090 So for I equals to zero as long as I is less than size. 62 00:04:41,530 --> 00:04:42,640 I plus, plus. 63 00:04:45,630 --> 00:04:48,850 OK, so now let's do it like this. 64 00:04:49,500 --> 00:04:53,430 So what should we do, what should we do? 65 00:04:53,460 --> 00:04:55,770 So let's first of all, construct the conditions. 66 00:04:55,770 --> 00:05:00,210 So if they are at index, I have the left index. 67 00:05:00,210 --> 00:05:05,250 What should be the left index here, i.e. minus one is less than a right index. 68 00:05:05,250 --> 00:05:10,740 I OK, if that's the case then maybe we can conclude something. 69 00:05:11,220 --> 00:05:17,520 But the problem here is basically should we start on the index from equals to zero, should we do it. 70 00:05:18,030 --> 00:05:24,790 Because in this case there will be a problem because we will try to access ARRL index minus one. 71 00:05:25,200 --> 00:05:29,190 So I will start from I equals to one. 72 00:05:29,460 --> 00:05:31,060 OK, awesome. 73 00:05:31,230 --> 00:05:37,770 So if there are at index minus one is less than this one, then no problem. 74 00:05:37,770 --> 00:05:39,530 Nothing can be concluded out of it. 75 00:05:39,780 --> 00:05:40,220 Right. 76 00:05:40,830 --> 00:05:48,180 But let's say that also we have like this condition for the really sorted and also we have like this 77 00:05:48,180 --> 00:05:56,440 condition for the source of the rain, but they do not pretty much give you anything. 78 00:05:56,460 --> 00:06:04,560 OK, we have to make some assumptions for at least one pair that does not satisfy these conditions. 79 00:06:04,950 --> 00:06:06,120 And what do I mean by that? 80 00:06:06,690 --> 00:06:08,250 Let's simply start with this one. 81 00:06:08,280 --> 00:06:09,930 OK, so let's start with this one. 82 00:06:09,960 --> 00:06:15,120 So if you are on the left is not less than or. 83 00:06:16,970 --> 00:06:22,920 Or are equals to the element on the ride then in this case? 84 00:06:22,940 --> 00:06:28,480 OK, in this case, but in this case we can ride down like this. 85 00:06:28,520 --> 00:06:32,840 So the element on the left is greater than the element on the ride. 86 00:06:32,840 --> 00:06:40,320 So element on the left is greater than the element of the ride. 87 00:06:41,390 --> 00:06:47,990 OK, so that means that neither of these conditions or this one is satisfied and that means that. 88 00:06:49,040 --> 00:06:51,890 Basically, the array is not sorted at all. 89 00:06:52,120 --> 00:06:54,160 OK, we can also create some fled. 90 00:06:54,640 --> 00:06:58,640 OK, let's say flag and we will use this flag as something like this. 91 00:06:58,940 --> 00:07:00,680 So flag equals to two. 92 00:07:01,070 --> 00:07:08,140 And if flag equals to two, then two means to means that it's like really sorted. 93 00:07:08,750 --> 00:07:11,000 That's just our conventions. 94 00:07:11,330 --> 00:07:20,750 One will mean that the array is sorted and zero will mean that the array is not sorted at all. 95 00:07:20,960 --> 00:07:23,480 OK, just some flag for our. 96 00:07:23,480 --> 00:07:27,880 Of course there are additional options to solve this exercise, but I'm going with this one. 97 00:07:28,400 --> 00:07:34,460 So if you are on the left is greater than B.C., are that then the value on its right. 98 00:07:34,790 --> 00:07:37,340 So then definitely we can say the following thing. 99 00:07:37,340 --> 00:07:38,330 We can say that. 100 00:07:39,350 --> 00:07:48,830 The flag should be equal to zero as well as we can, also can't break out of this loop not to execute 101 00:07:48,830 --> 00:07:52,700 any anything else, because that's does not make any sense. 102 00:07:52,780 --> 00:07:54,800 OK, all right. 103 00:07:54,810 --> 00:07:59,450 So if that's the condition for r for what? 104 00:07:59,450 --> 00:08:01,420 For the not sorted. 105 00:08:01,640 --> 00:08:03,260 OK, so there you go. 106 00:08:03,260 --> 00:08:05,660 You've basically found out that it's not sorted. 107 00:08:06,200 --> 00:08:13,400 You just found at least one pair that does not satisfy neither of these conditions or this then in this 108 00:08:13,400 --> 00:08:20,840 case, put the flag to be zero and break out of this loop and go basically here and printed that the 109 00:08:20,840 --> 00:08:22,100 arrays not sorted at all. 110 00:08:22,370 --> 00:08:24,840 OK, so that's something we took care of. 111 00:08:25,220 --> 00:08:32,030 Now we have to like to understand how can we make the distinguish distinction between the sorted and 112 00:08:32,030 --> 00:08:33,020 the really sorted? 113 00:08:33,560 --> 00:08:36,830 OK, so for that we will use another condition. 114 00:08:37,830 --> 00:08:45,810 And we will say that if the element on the left equals to the element on the right, OK, meaning it 115 00:08:45,810 --> 00:08:53,210 does not satisfy the condition of the really sort because there is at least one pair that is not OK, 116 00:08:53,220 --> 00:09:01,830 that is not are basically satisfies the condition that the element on the left has to be less than the 117 00:09:01,830 --> 00:09:02,930 element on the right. 118 00:09:03,340 --> 00:09:09,060 OK, then in this case we can definitely say that flag will be equal to one. 119 00:09:09,210 --> 00:09:13,440 OK, so that's basically associated with the sorted. 120 00:09:13,440 --> 00:09:14,850 OK, but not really. 121 00:09:14,850 --> 00:09:18,120 Sort of not really sorted. 122 00:09:19,830 --> 00:09:20,750 OK, is that clear. 123 00:09:22,320 --> 00:09:26,310 And if that's the case, should we also use the break. 124 00:09:26,910 --> 00:09:28,230 Well what do you think? 125 00:09:28,680 --> 00:09:34,770 Absolutely not, because there may come also another pair that this condition will be satisfied for 126 00:09:34,770 --> 00:09:34,910 it. 127 00:09:34,920 --> 00:09:43,440 OK, but this condition basically said to us that our first assumption, OK, and our base base case 128 00:09:43,440 --> 00:09:47,610 assumption that we will assume that the array is really sorted. 129 00:09:47,920 --> 00:09:56,040 And if we will find out at least one OK, at least one pair, that does not satisfy the condition that 130 00:09:56,040 --> 00:10:03,810 any element on the left is less than the element on the right, then basically if we found out like 131 00:10:03,810 --> 00:10:09,330 this, so the element on the left equals to the element on the right, then in this case we can assume 132 00:10:09,330 --> 00:10:12,240 that the array may also still be sorted. 133 00:10:12,240 --> 00:10:14,330 OK, but not really sorted. 134 00:10:14,970 --> 00:10:21,630 And if we found out that there is at least one pair that satisfy this conviction that the element on 135 00:10:21,630 --> 00:10:24,120 the left is greater than the element on there, right. 136 00:10:24,450 --> 00:10:30,300 Then basically we can say for sure that the array is not sorted and it doesn't matter what elements 137 00:10:30,300 --> 00:10:31,530 will come next. 138 00:10:32,220 --> 00:10:37,170 So that's the loop of the body that we have here. 139 00:10:37,260 --> 00:10:38,220 I hope nothing. 140 00:10:38,220 --> 00:10:39,860 I didn't miss anything. 141 00:10:40,560 --> 00:10:44,940 And now we will simply again conclude this exercise by just updating. 142 00:10:44,940 --> 00:10:46,740 These are flags. 143 00:10:47,890 --> 00:10:54,730 And this can be done in the following way, so if Fleg equals equals two, one, two, two. 144 00:10:54,790 --> 00:10:57,070 OK, so the array is really sorted. 145 00:10:57,230 --> 00:10:59,460 The flag remained the same. 146 00:10:59,860 --> 00:11:06,610 And if flag equals to one, then we can say that the rate is sorted but not really sorted. 147 00:11:07,210 --> 00:11:13,600 And if flag equals to zero, then in this case the array is not sorted at all. 148 00:11:13,820 --> 00:11:15,820 OK, so we can also use here LC. 149 00:11:16,120 --> 00:11:16,410 Right. 150 00:11:16,780 --> 00:11:20,240 And also Elzy also. 151 00:11:20,830 --> 00:11:28,020 So let's just executed and see if it basically works as expected and we can get all the information. 152 00:11:28,030 --> 00:11:29,110 So let's go. 153 00:11:29,110 --> 00:11:30,320 Where is our example. 154 00:11:30,340 --> 00:11:34,570 So one, two, five, seven in 10. 155 00:11:34,570 --> 00:11:36,830 I'm just executing this example one. 156 00:11:37,810 --> 00:11:41,210 So the array is really sorted. 157 00:11:41,230 --> 00:11:42,730 Congratulations. 158 00:11:42,760 --> 00:11:43,180 Awesome. 159 00:11:43,210 --> 00:11:46,120 So the first example seems to work as expected. 160 00:11:46,840 --> 00:11:49,780 Let's just now try the second example. 161 00:11:49,780 --> 00:11:50,680 It goes like this. 162 00:11:50,710 --> 00:11:54,220 So one, two, two, five and 10. 163 00:11:54,790 --> 00:12:03,730 And they should printers that the the array is sorted, but not really sort of the array sorted because 164 00:12:03,730 --> 00:12:12,190 we have a pair here of two numbers that the right or the next number is not greater than the previous 165 00:12:12,190 --> 00:12:12,410 one. 166 00:12:13,000 --> 00:12:14,720 So the array is sorted. 167 00:12:15,220 --> 00:12:20,580 And finally, for our third example here, come here, come here, come here. 168 00:12:20,620 --> 00:12:21,310 OK, you're here. 169 00:12:21,340 --> 00:12:21,600 OK. 170 00:12:22,330 --> 00:12:28,570 So for our final example, we will use like one, two, five, three and ten. 171 00:12:29,140 --> 00:12:31,100 And what do you expect to see here? 172 00:12:31,360 --> 00:12:37,600 Basically, you expect to see here one thing, a message of not sort of printed through the screen. 173 00:12:37,990 --> 00:12:38,860 And why is that? 174 00:12:39,010 --> 00:12:42,220 That's because we have a pair, at least one pair. 175 00:12:42,250 --> 00:12:48,100 OK, there maybe also more pairs that satisfy this condition, but at least one pair. 176 00:12:48,100 --> 00:12:55,900 So that says that the previous number or the number on the left or the previous number is greater than 177 00:12:55,900 --> 00:12:57,430 the next value. 178 00:12:57,460 --> 00:12:59,410 OK, so five is greater than three. 179 00:12:59,420 --> 00:13:06,500 So it kind of stops the increasing between every pair of the numbers. 180 00:13:06,530 --> 00:13:11,890 OK, so two to five is OK, five to three and that's a decrease. 181 00:13:12,830 --> 00:13:18,410 And that's why I think there should be a message of the array is not sorted. 182 00:13:19,310 --> 00:13:25,550 So they hope this explanation is clear to you guys, OK, that's just the simple program that we've 183 00:13:25,550 --> 00:13:29,480 written together with a few examples that we've seen right here. 184 00:13:29,960 --> 00:13:33,140 And there is basically some logic. 185 00:13:33,140 --> 00:13:38,230 There is also there are also other solutions to solve it. 186 00:13:38,290 --> 00:13:40,250 OK, I guess maybe some of them are. 187 00:13:40,890 --> 00:13:42,140 Oh, sure there are. 188 00:13:42,230 --> 00:13:43,420 Some of them are longer. 189 00:13:43,430 --> 00:13:50,890 OK, but that's just the trivial solution that I prefer to be using for these basic scenarios. 190 00:13:51,260 --> 00:13:52,580 So three options. 191 00:13:52,610 --> 00:13:59,390 So I was just and I make some assumptions that if flag equals to two, it will be really sorted, one 192 00:13:59,390 --> 00:14:01,730 sorted and not sorted at all. 193 00:14:02,120 --> 00:14:09,050 And I simply iterate over all the elements of this array every time taking a pair of elements and element 194 00:14:09,050 --> 00:14:17,670 on the left and then the element on the right and basically asking some conditions to like to do ask 195 00:14:17,690 --> 00:14:23,300 at least and to find to try finding at least one pair that does not satisfy a condition for a given 196 00:14:23,300 --> 00:14:24,740 status, for a given flag. 197 00:14:25,040 --> 00:14:31,810 And based on this result, to make some assumptions whether I should change the flag to zero or two 198 00:14:31,820 --> 00:14:32,270 one. 199 00:14:32,660 --> 00:14:38,510 And you can see also that the flag cannot be returned to be equal to your flag equals to two, because 200 00:14:38,690 --> 00:14:43,760 there was at least something, some period that changed the flag from flag equal to two. 201 00:14:45,200 --> 00:14:46,660 And yeah. 202 00:14:46,790 --> 00:14:48,440 So thank you guys for watching. 203 00:14:48,470 --> 00:14:49,360 My name is Vlad. 204 00:14:49,400 --> 00:14:50,390 This is Alphatech. 205 00:14:50,720 --> 00:14:54,590 I hope you are doing great tonight on your own. 206 00:14:55,920 --> 00:15:01,440 Give me some feedback, some reviews, some comments, if you like the video and if you have any questions 207 00:15:01,980 --> 00:15:06,320 and until the next time we the exercises together, I wish you a great time. 208 00:15:06,330 --> 00:15:08,490 Productive learning, you know. 209 00:15:08,510 --> 00:15:09,110 I'll see you then. 19093

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