1
00:00:01,490 --> 00:00:02,180
Hi, everyone.

2
00:00:02,210 --> 00:00:06,430
So in the last few videos, we discussed how we can implement our own priorities.

3
00:00:07,100 --> 00:00:10,980
We discussed how we can write the code for implementing in place Cheapside.

4
00:00:11,540 --> 00:00:15,470
So in this video, we will try to learn about the inbuilt priority queue.

5
00:00:15,920 --> 00:00:21,230
So the priority is actually president didn't steal and attempted bribery in C++.

6
00:00:21,740 --> 00:00:23,430
So this inbuilt priority queue.

7
00:00:23,480 --> 00:00:26,750
So this is this is present in UCLASS.

8
00:00:29,810 --> 00:00:36,140
Now, if you want to solve a question using a priority, you so suppose in future, if there a question

9
00:00:36,620 --> 00:00:41,480
and in order to solve that question, you want to use priority queue, then you will not implement tried

10
00:00:41,570 --> 00:00:46,330
give yourself you're just likely use the prior deal that is implemented in the standard library.

11
00:00:47,240 --> 00:00:51,370
So now let's see how we can use the inbuilt priority queue.

12
00:00:52,550 --> 00:00:56,040
So first of all, what are the functions that we implemented ourselves?

13
00:00:56,480 --> 00:00:59,240
So I implement, we implemented a function is empty.

14
00:01:00,540 --> 00:01:06,720
Now, an inbuilt priority, guilt or dysfunction, is also present with the name empty again, there

15
00:01:07,110 --> 00:01:09,360
will be boolean, true or false is my cue.

16
00:01:09,370 --> 00:01:11,730
Importunate is my priority, QM, but they are not.

17
00:01:12,210 --> 00:01:14,910
Similarly, we implemented our function getset.

18
00:01:15,690 --> 00:01:18,320
So this function is also present in priority.

19
00:01:18,360 --> 00:01:24,660
GICLAS And the name is basically size, so this will return me an integer.

20
00:01:25,110 --> 00:01:26,430
So this will return integer.

21
00:01:27,420 --> 00:01:30,660
And similarly we implemented a function insert.

22
00:01:30,990 --> 00:01:35,670
Now insert function will take an element as input and it will insert into our prior dequeue.

23
00:01:36,180 --> 00:01:40,050
Similarly, we also have inbuilt function push.

24
00:01:41,250 --> 00:01:48,660
And this Bush can take the element of any type Sorte element, so actually this class, so this private

25
00:01:48,810 --> 00:01:51,060
class, so this is implemented using template.

26
00:01:52,380 --> 00:01:58,740
So that's why you type and element now, we also implemented a function, get a minimum.

27
00:02:02,530 --> 00:02:08,949
Similarly, there is also a function in private vehicles and of the function is top, so I will call

28
00:02:08,949 --> 00:02:11,650
the function top and it will give me the Menom element again.

29
00:02:11,650 --> 00:02:18,000
The type will be the sort DAYTOP These the type of Lesedi type of the element, simple.

30
00:02:18,760 --> 00:02:24,910
Now reimplemented one more function, remove minimum function so reimplemented remove minimum function.

31
00:02:24,910 --> 00:02:31,880
And what it does is so in our implementation it will lead the element and it will also return the element.

32
00:02:31,900 --> 00:02:34,800
So in our implementation we were returning integer.

33
00:02:35,050 --> 00:02:39,640
So in our implementation it will remove the element and it will also give me that element.

34
00:02:40,120 --> 00:02:44,100
But in the inbuilt protocol, it will just pop out that element.

35
00:02:44,110 --> 00:02:45,580
So why'd Bob?

36
00:02:48,280 --> 00:02:53,860
So basically, this bulb function, it will just remove the element, it will not give us the element,

37
00:02:53,990 --> 00:02:58,840
but in our implementation, we implemented it in such a way that it will be the element and it will

38
00:02:58,840 --> 00:03:00,850
also return the little element.

39
00:03:02,440 --> 00:03:05,740
Now, let's try to use our in particular to see the cold.

40
00:03:08,010 --> 00:03:13,980
So first of all, this protocol is present in UCLASS, so I have to include that class in order to use

41
00:03:13,980 --> 00:03:14,610
prior to Q.

42
00:03:19,290 --> 00:03:29,670
Now, the syntax is very simple, we have to write priority due, so Priority and Corkill and the name

43
00:03:29,670 --> 00:03:36,000
is Piku, but obviously this is wrong because this particular priority class is actually a template,

44
00:03:36,660 --> 00:03:37,370
so template.

45
00:03:37,380 --> 00:03:40,220
So that means you have to give the type.

46
00:03:40,230 --> 00:03:43,260
So suppose I want to create a priority queue often teachers.

47
00:03:44,570 --> 00:03:46,580
And now let us push some elements.

48
00:03:48,710 --> 00:03:52,460
So, again, for pushing the element, I have a function I haven't built function, be good art.

49
00:03:52,470 --> 00:03:58,220
Bush and I will give Integer here because I have given I am creating Plastiki, often tedious.

50
00:03:58,230 --> 00:04:00,950
So that's why this push function will take integers and put.

51
00:04:02,330 --> 00:04:10,700
So let's say 16 and let's copy this Bush and let us insert more elements.

52
00:04:18,260 --> 00:04:25,100
So let's see, the elements are one, then let's see 167, then let's see.

53
00:04:26,700 --> 00:04:33,570
I want to insert seven, then let's say 45, then let's say 32.

54
00:04:36,340 --> 00:04:43,090
So I am inserting I am pushing six elements into my priority queue, simple, let's see other functions

55
00:04:43,180 --> 00:04:44,940
that involve function of radical glass.

56
00:04:45,400 --> 00:04:47,960
So let us first try to print this size.

57
00:04:48,490 --> 00:04:52,020
So forgetting the size, we have inbuilt function size.

58
00:04:52,540 --> 00:04:55,240
So I will write be good size.

59
00:04:55,930 --> 00:04:59,160
So the size is again inbuilt function of our practical class.

60
00:05:00,190 --> 00:05:06,700
So it will return me six because I am pushing six elements to the size of our priority is actually six.

61
00:05:06,970 --> 00:05:07,540
Simple.

62
00:05:12,680 --> 00:05:20,600
Now, let's try to find out the top element, so I am trying to pin the top elements of what should

63
00:05:20,600 --> 00:05:24,260
be my output to the function is be good top.

64
00:05:25,190 --> 00:05:29,990
So the stop function, it will return me the element present at the root element.

65
00:05:30,770 --> 00:05:32,150
So what should be my output?

66
00:05:32,690 --> 00:05:34,220
So one thing to notice here is.

67
00:05:36,980 --> 00:05:45,040
Basically, so this output depends upon so this element depends upon whether you are creating a minimum

68
00:05:45,260 --> 00:05:47,040
or you are creating a maximum heap.

69
00:05:47,660 --> 00:05:50,150
So this is actually maximum cheap.

70
00:05:51,710 --> 00:05:54,110
This is the index for creating maximum.

71
00:05:55,160 --> 00:06:00,120
It also discuss how we can write this index for the minimum heap, but not in this video.

72
00:06:00,650 --> 00:06:02,080
So this is actually makes me.

73
00:06:02,510 --> 00:06:09,320
So what will happen to these elements are present in maximum heap and size will give me the six and

74
00:06:09,320 --> 00:06:10,130
picador top.

75
00:06:10,160 --> 00:06:11,460
So what it will give me.

76
00:06:11,480 --> 00:06:12,910
So it will give me the root element.

77
00:06:12,920 --> 00:06:16,370
And in case of maximum, the root element is the largest element.

78
00:06:17,900 --> 00:06:26,240
And the largest element is actually 167, so the output of this line is going to be 167 simple.

79
00:06:26,870 --> 00:06:31,590
So now let us try to bring all the elements so we can use.

80
00:06:31,850 --> 00:06:36,130
So this will be one six to seven because this is actually maximum cheap.

81
00:06:37,670 --> 00:06:42,950
Again, we will also discuss how we can write the code for the minimum, but not in this video.

82
00:06:46,140 --> 00:06:52,260
So, again, very simple and so vital priority queue is not empty, but we have to do so, we will get

83
00:06:52,560 --> 00:06:54,300
one by one and we will bring the element.

84
00:06:55,830 --> 00:07:03,450
So, again, she would be good or so it will give me the top element, basically the largest element,

85
00:07:03,690 --> 00:07:07,700
and then what I will be good artpop, I will remove this largest element.

86
00:07:08,640 --> 00:07:13,710
So what I'm doing, I am blending the topmost element, which is going to be the largest element, and

87
00:07:13,710 --> 00:07:16,370
then I am popping out the Taliban symbol.

88
00:07:17,040 --> 00:07:19,050
So let's see what will be our output.

89
00:07:23,600 --> 00:07:25,460
OK, so this is spelling mistake.

90
00:07:27,260 --> 00:07:28,190
Now, this is correct.

91
00:07:31,910 --> 00:07:33,920
OK, so compilation error.

92
00:07:42,560 --> 00:07:51,220
So as we can see now, let's try to analyze our output, so as I told you so this is actually a maximum

93
00:07:51,230 --> 00:07:51,500
EHP.

94
00:07:52,830 --> 00:07:58,020
I am pushing six elements, so that's why the size is going to be six and the topmost element is going

95
00:07:58,020 --> 00:07:59,160
to be 167.

96
00:07:59,970 --> 00:08:08,590
So this is my hip maximum 16, then one, then 167, then seven, then 45 and then 32.

97
00:08:09,360 --> 00:08:16,350
So while prior to queue is not empty, so picador top, so top most elements one six to seven to bring

98
00:08:16,350 --> 00:08:18,710
the topmost element and remove the top most elements.

99
00:08:18,710 --> 00:08:19,800
So 167.

100
00:08:19,800 --> 00:08:21,450
So this is more and six to 167.

101
00:08:21,720 --> 00:08:26,990
Then again prior to Goozner temporary bring to the up most elements or top master element is 45.

102
00:08:27,690 --> 00:08:30,590
So after printing the element also remember that element.

103
00:08:30,900 --> 00:08:32,270
So let's a 45 here.

104
00:08:32,549 --> 00:08:35,370
Similarly, again, the priority is not empty.

105
00:08:35,370 --> 00:08:38,520
So the maximum element and pop the maximum element.

106
00:08:39,799 --> 00:08:46,490
Bring the maximum element and maximum element, bring the maximum element and maximum element into the

107
00:08:46,490 --> 00:08:48,560
maximum element and maximum element.

108
00:08:48,590 --> 00:08:54,290
And finally, this condition will become false because now my priority is actually empty.

109
00:08:54,830 --> 00:08:58,370
So I will come out of this very simple.

110
00:09:00,250 --> 00:09:05,230
Now, again, if you want to discuss so what is their time, complexity for push function, so we have

111
00:09:05,230 --> 00:09:07,600
this question many times the time complexities log of in.

112
00:09:08,350 --> 00:09:11,720
So in prior to kill, all the functions are going to take longer in time.

113
00:09:11,740 --> 00:09:13,970
So Bush is going to take longer in time.

114
00:09:14,320 --> 00:09:15,250
Now the sites function.

115
00:09:15,270 --> 00:09:16,210
So this is constant.

116
00:09:16,880 --> 00:09:19,870
We are just returning the site again, top element.

117
00:09:19,870 --> 00:09:21,530
So we just have a and root element.

118
00:09:21,570 --> 00:09:22,990
So again, this is constant.

119
00:09:23,710 --> 00:09:26,770
So again, this empty function, this is also constant.

120
00:09:28,340 --> 00:09:33,440
So, again, this top function constant, not this pop function, so this pop is actually removable,

121
00:09:33,440 --> 00:09:34,370
so this is log-in.

122
00:09:37,010 --> 00:09:37,460
So.

123
00:09:38,850 --> 00:09:45,020
This empty function, the societys function, they are constant function, so you get the minimum function

124
00:09:45,030 --> 00:09:53,520
is also constant and this push and pop, so this function is actually logoff and and what is and is

125
00:09:53,520 --> 00:09:57,780
basically the total number of elements present in our priority queue.

126
00:09:58,980 --> 00:10:02,160
So is the total number of elements in our Pritikin.

127
00:10:03,640 --> 00:10:10,760
So now we know how to write the code, how to use our inbuilt priority queue, inbuilt maximum priority

128
00:10:10,780 --> 00:10:13,510
queue and we will discuss in the next video.

129
00:10:14,620 --> 00:10:22,480
How we can write, how we can write the code for using minimum hip, so minimum is also in, but the

130
00:10:22,480 --> 00:10:23,870
syntax is a little bit different.

131
00:10:24,130 --> 00:10:29,440
So in this video we discussed only makes one hip and all the functions will be same in the mix.

132
00:10:29,440 --> 00:10:31,510
And he pandamonium hip, all the function will be same.

133
00:10:31,510 --> 00:10:36,730
But just the way of creating is a little bit different, which you will discuss in the next few videos.

134
00:10:37,540 --> 00:10:38,520
So I will see you there.

135
00:10:38,710 --> 00:10:39,190
Bye bye.

