Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,180 --> 00:00:06,690
What is going on, beautiful people, what is going on, ladies and gentlemen, and in this video,
2
00:00:06,690 --> 00:00:14,490
what we are going to do is simply to write a function and some sort of a program to test the doubt that
3
00:00:14,490 --> 00:00:17,750
will receive to a race of the same size.
4
00:00:17,760 --> 00:00:23,910
OK, so the function is going to receive to erase all of the same size.
5
00:00:24,420 --> 00:00:31,890
And then what the function is going to do is simply to swap between each and any of the values of these
6
00:00:31,890 --> 00:00:32,690
to erase.
7
00:00:32,700 --> 00:00:41,850
So swap between their values, between their values, just one by one.
8
00:00:42,040 --> 00:00:47,430
OK, and the time complexity of this thing is going to be O of end.
9
00:00:47,620 --> 00:00:51,590
OK, so basically M represents the size of the array.
10
00:00:51,600 --> 00:00:57,990
So we are simply going to iterate over both of these arrays and simply do swap between the values of
11
00:00:57,990 --> 00:00:59,760
each and any of them.
12
00:01:00,210 --> 00:01:07,410
So for that one we have to do is simply and I just make sure that you understand these ofin because
13
00:01:07,680 --> 00:01:15,240
we are going to do it in just one operation or a couple of operation, but not is the size of the array
14
00:01:15,240 --> 00:01:17,050
specifies in the next video.
15
00:01:17,310 --> 00:01:24,300
So for now, what we are going to do is simply to define size and we are going to define some size,
16
00:01:24,300 --> 00:01:29,510
let's say five, OK, and we are going to use the inside of this main function.
17
00:01:29,520 --> 00:01:31,470
We are going to create to erase.
18
00:01:31,500 --> 00:01:36,980
So end array one, OK, and we will need to be of size.
19
00:01:37,590 --> 00:01:39,500
Let's put here some values.
20
00:01:39,500 --> 00:01:42,950
So one, three, six, eight and 10.
21
00:01:43,350 --> 00:01:48,250
And in the second array, what we are going to do is put some other values.
22
00:01:48,510 --> 00:01:56,400
So for example, let's put it like two again, two, four, 11 and 17.
23
00:01:56,430 --> 00:02:01,230
OK, so that's what we are going to do and to hold for the secondary.
24
00:02:01,560 --> 00:02:02,480
So awesome.
25
00:02:02,610 --> 00:02:05,340
We created our to erase in.
26
00:02:05,340 --> 00:02:12,720
What we are going to do now is simply to swap between the values and how we are going to do that.
27
00:02:13,020 --> 00:02:19,770
We are going to write down a function that first of all, is responsible for making just the swap between
28
00:02:19,770 --> 00:02:20,830
two integers.
29
00:02:20,850 --> 00:02:23,590
You do remember how this function looks like, don't you?
30
00:02:23,910 --> 00:02:29,610
So these function is going those like this a wide swap, OK, and wide swap.
31
00:02:29,610 --> 00:02:36,120
And there you go in star value one and end star value two.
32
00:02:36,840 --> 00:02:38,100
And the function goes like this.
33
00:02:38,100 --> 00:02:44,460
So in Tampa and Tampa equals to you value one end of value.
34
00:02:44,460 --> 00:02:54,860
One now equals two value two and value two equals now two to what is equal to two temp.
35
00:02:55,070 --> 00:03:01,740
OK, so if I'm not mistaken here or in any part mystically, guys, this is something we've done in
36
00:03:01,740 --> 00:03:06,270
one of our previous videos is just the basic swap function between two values.
37
00:03:06,660 --> 00:03:12,420
And the reason we are using pointers here, I'm not going to remind it, are right now because we don't
38
00:03:12,420 --> 00:03:13,950
have time in this exercise.
39
00:03:14,140 --> 00:03:19,440
But if you have questions, feel free to ask and I will try to redirect you to the exact video where
40
00:03:19,440 --> 00:03:21,960
we talked about everything related to that.
41
00:03:22,560 --> 00:03:29,610
So we have this web function and this function will not swap between all the elements of the array.
42
00:03:29,610 --> 00:03:29,940
Right.
43
00:03:30,120 --> 00:03:37,460
We need to call the swap function into for each pair of these values.
44
00:03:37,740 --> 00:03:44,520
So what we can do is simply also create additional array and an additional function and call it void
45
00:03:44,760 --> 00:03:53,540
swap o m OK o and ease the time complexity swap and swap arrays instead of like this.
46
00:03:53,570 --> 00:03:55,080
Oh OK.
47
00:03:55,080 --> 00:03:58,620
So simply it's, it's saying let me explain it to you guys.
48
00:03:58,630 --> 00:04:00,690
So first of all let's receive both of the arrays.
49
00:04:00,720 --> 00:04:08,430
So int IRR one end point or two and we know the size is this size the defined here.
50
00:04:08,820 --> 00:04:15,360
So we can also use that or we could have got it as arguments for for, as parameters for this function.
51
00:04:16,350 --> 00:04:19,020
OK, so the function is going to be like this.
52
00:04:19,050 --> 00:04:28,170
So void printing are simply will receive the array so into Jutras and we know the size here is defined
53
00:04:28,170 --> 00:04:37,980
so it doesn't really matter and, and I or I equals to zero as long as I use less than size I plus plus
54
00:04:38,670 --> 00:04:48,280
we are going to print the values or print half percentage percentage the and we are going to print here
55
00:04:48,330 --> 00:04:55,410
at I and also just to specify that we are done with this printing, just print in your line, print,
56
00:04:55,410 --> 00:04:57,510
backslash and at the end.
57
00:04:58,620 --> 00:04:59,210
Awesome.
58
00:04:59,340 --> 00:04:59,970
So we have.
59
00:05:00,030 --> 00:05:02,300
Three functions, you see how you improved.
60
00:05:02,330 --> 00:05:09,030
I mean, there were times that we just were struggling to write one function, one basic function,
61
00:05:09,030 --> 00:05:10,560
and we just use this machine.
62
00:05:10,850 --> 00:05:16,380
And now we have created three functions, I think, in just a couple of minutes, and we are ready to
63
00:05:16,380 --> 00:05:20,570
move on and to use all of them to solve our problems.
64
00:05:20,570 --> 00:05:31,590
So what we are going to do is print F values before swap OK, or array values, array values before
65
00:05:31,590 --> 00:05:32,110
the swap.
66
00:05:32,940 --> 00:05:41,100
So what we are going to do now is to call the printer our function for an array one also do the same
67
00:05:41,100 --> 00:05:42,630
for a year or two.
68
00:05:42,810 --> 00:05:50,340
OK, you're with me and once we are done we are going to call the function swap array on and to use
69
00:05:50,340 --> 00:05:54,720
it with array one and every two gay guys.
70
00:05:55,470 --> 00:06:00,300
And what we are doing here is simply sending the address of the first element here.
71
00:06:00,300 --> 00:06:07,920
And this is the address of the second element to here, making sure that simply all all of the function
72
00:06:08,460 --> 00:06:11,850
is going to do is to just swap between the values.
73
00:06:12,480 --> 00:06:14,490
So let's build and run it.
74
00:06:14,610 --> 00:06:17,880
OK, so build and run and there you go.
75
00:06:18,060 --> 00:06:25,890
Array values before swap are one three six eight, 10, four array number one and two to four.
76
00:06:25,890 --> 00:06:28,080
You live in 17 for array two.
77
00:06:28,470 --> 00:06:35,910
But after the swap has occurred, we will see that every one contains two two four, 11, 17 and the
78
00:06:35,910 --> 00:06:40,770
array two has all the values that previously everyone had.
79
00:06:40,860 --> 00:06:42,930
So that's freaking amazing, guys.
80
00:06:43,290 --> 00:06:45,930
And once again, I want to explain what happened here.
81
00:06:45,930 --> 00:06:47,370
Let's take another look.
82
00:06:47,380 --> 00:06:50,970
OK, so we created, first of all, array one in every two.
83
00:06:51,240 --> 00:06:57,210
Here they are behind the scenes and then we printed their values, OK, and there you go.
84
00:06:57,390 --> 00:07:01,740
And then we call this Warlpiri in oh of A..
85
00:07:01,740 --> 00:07:03,930
And give it a one in array two.
86
00:07:04,290 --> 00:07:12,930
So we got here and simply iterated over all the elements of these arrays, one by one, taking each
87
00:07:12,930 --> 00:07:15,480
time a value at a specific index.
88
00:07:15,480 --> 00:07:22,470
So ARRL Index zero and here are two at index zero and making swap between both of them.
89
00:07:22,470 --> 00:07:25,020
So that's what we got on the first iteration.
90
00:07:25,500 --> 00:07:30,230
That's what we got on the second iteration after swapping these two values and so on.
91
00:07:30,690 --> 00:07:32,640
So that's basically how we did it.
92
00:07:32,670 --> 00:07:40,700
We sent here the address of a given value in this array of a given element and simply used there are
93
00:07:40,920 --> 00:07:42,810
the common swap function.
94
00:07:43,050 --> 00:07:51,360
And what was the time, complexity, the time complexity was o of and or of size of this array, because
95
00:07:51,360 --> 00:07:54,260
we each created over all the elements of this ring.
96
00:07:54,420 --> 00:07:58,530
And in one of the next videos I'm going to show you some deep and trig.
97
00:07:59,850 --> 00:08:05,250
Sometimes interviewers like to ask this question on the interview questions.
98
00:08:05,730 --> 00:08:11,820
It's going to be a little bit different question, but we are going to see how we can like I don't know
99
00:08:11,820 --> 00:08:18,480
if it's called cheating or tweaking or whatever to swap to given a raise that after we kind of close
100
00:08:18,480 --> 00:08:26,010
our eyes and open it up, we will see that both arrays have been changed and we can access them like
101
00:08:26,010 --> 00:08:26,580
like this.
102
00:08:26,580 --> 00:08:33,930
But all of this operation will be done in just two or three lines of code without using any for a loop
103
00:08:33,930 --> 00:08:39,120
and without depending our answer on the size of the array.
104
00:08:39,420 --> 00:08:44,580
So that's very interesting topic that will cover hopefully in the future.
105
00:08:44,940 --> 00:08:46,980
So thank you guys for watching.
106
00:08:46,980 --> 00:08:48,480
Keep on practicing.
107
00:08:48,660 --> 00:08:50,310
Keep on moving forward.
108
00:08:50,310 --> 00:08:54,660
And yeah, I, I think we are done for this video.
109
00:08:54,780 --> 00:08:55,320
Bye bye.
11007
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.