- 1 day ago
Transcript
00:00Hi everyone! In this chapter, we are going to study a new data structure which is called Heaps or it
00:05is called Priority Cues. Now Heaps is a new data structure within Java and Heaps means that in English there
00:12is a hole. Like you have added a lot of numbers, so it will take a mountain type structure. Or
00:18a French Fries heap that I have shown you.
00:22So, we use heap data structure and create another data structure which we call priority queues. So, first of all,
00:28we will learn what is the concept of priority queues. After that, we will learn what is the concept of
00:32heaps, in which we will clear that in the form of heap, a priority queue will be implemented internally in
00:38Java. First of all, let's talk about
00:41Priority Queues concept of Queues. Now, Queues, we didn't know what happens. Queues is a line. If a lot of
00:47people are in a line, we usually call Queues in English. And what does Priority mean? Priority is a preference
00:54order. That means if students have a college admission to a student, what does that mean? They submit an application
00:59to students. Do you think this is my college? Which many students have applied.
01:06The first student whose rank is 5k, the second student whose rank is 15k, one student whose rank is 500k,
01:14one student whose rank is 1.5 lakh, one student whose rank is 1.5 lakh.
01:18So many students have different ranks in this way. Now what happens in college? Seats are limited. So if there
01:26are two seats in college, then the first seat will be reduced. So the first seat will go to this
01:32500 rank and the second seat will go to this 5,000 rank. So if college has a priority that
01:39if two people can fit in the seat, if two people can take admission in the seat, then which two
01:46will be set?
01:48The priority is given to the rank, the priority is given to the rank, the priority is given to the
01:52rank, the priority is given to the rank, the priority is given to the rank, it is given to the
01:57rank, it is given to the rank, it is given to the rank, it is given to the rank, it
01:59is given to the rank, it is given to the rank
02:03What happened before the CUT? On the basis of the percentage of admission, we thought that someone has 89 percent,
02:08someone has 72 percent, someone has 65 percent, someone has 54 percent, someone has 99 percent. So in this way,
02:17in the college, there are two seats. So these two seats will go to this one, which will go to
02:2199 percent and which will go to 89 percent. So in this way, what did he do? The percentage of
02:27high, he gave him more priority.
02:29So priority can be different. It can be more priority in rank and percentage in percentage. So basically, on the
02:38basis of priority, we have to sort our data. Like if you create an automatic admission system for your college.
02:45What do colleges do now? Colleges take your application for many children's children. And it can be done if you
02:51don't see a teacher manually in any college. There is an online system that has a lower rank which will
02:55automatically be allocated to them.
03:01There are automatic systems that are made on your website, which are automatically seat assigned. For real-life priority problems,
03:12I need a data structure that goes on a priority basis. That's why I have a concept of priority cues
03:22here.
03:22and then another example is that you have a hospital in the hospital there are limited beds in the hospital
03:28there are limited beds in the hospital or if we have covid times there was a lot of limited beds
03:32in the hospital there was a single bed in the hospital and you have a lot of patients who have
03:39been lined up one patient who has a regular check-up
03:45he has been injured, he has been injured, he wants to admit to him, there is one patient who has
03:52been fractured and one patient who has been accident
03:57So, what will the hospital do? The hospital is more severe, the case is more bad, the situation is urgent,
04:03it will give you priority. So, the accident case is the first priority. If someone else is empty, then the
04:09fracture case will give you. If someone else is empty, then the cold case will give you. If someone else
04:14is empty, then the regular check-up will give you priority. So, the priority is on any basis. Health, rank,
04:22rank, percentage, marks, marks.
04:26On the height, there is a priority on the height, which will stand in line, which will stand in line,
04:29which will stand in line, which will stand in line. On the age basis, we can sort the data using
04:36this structure called priority queue. What is priority queue? It is a normal queue. As we imagine, priority queue looks
04:44like something like this. And I have given it a lot of students. In the data, I have given it
04:50a name, age, role number, all these things. I have given it a rank with it.
04:54One student rank is 5K, one student rank is 65K, one student rank is 70K, one rank is 1 lakh,
05:01one rank is 30.
05:02So what will ensure the priority queue? It is sorted according to the basis of the rank, so the minimum
05:06priority thing will always come to the front. This is my front, this is my rear. From the front, there
05:13are elements from the front. So what will happen if the 30th rank is the smallest, so it will always
05:17be 30 in priority queue. Later the elements can be jumbled in fashion, but in priority queue the highest priority
05:26will be by default, which will be my 30th rank.
05:29If I believe that I have deleted 30 of my priority queue. So now my priority queue will be more
05:33than 5. Because this is my highest priority item. This is now the highest priority item. So here's the concept
05:42of priority queue. Which we implement in Java as a new data structure.