Lecture 74: Heaps in C++ || Heap Sort || Insertion/Deletion in Heap || Priority Queue STL
In this Video, we are going to learn about Heaps, Insertion/Deletion , heapify algo, Heap Sort algorithm etc.
There is a lot to learn, Keep in mind “ Mnn bhot karega k chor yrr apne se nahi hoga ya maza nahi aara, Just ask 1 question “ Why I started ? “
Visit Crio: www.crio.do/redeem/6ce859d/
Discord Server Link: / discord
Course Flow: whimsical.com/dsa-4-placement...
Notes Link: drive.google.com/drive/folder...
Slides Link: drive.google.com/file/d/1pGxC...
Code Links: github.com/loveBabbar/CodeHel...
Questions Links:
- Build Min-Heap: www.codingninjas.com/codestud...
Do provide you feedback in the comments, we are going to make it best collectively.
Connect with me here:
Instagram: / lovebabbar1
Twitter: / lovebabbar3
Telegram Group Link: Love Babbar CODE HELP
telegram.me/lovebabbercodehelp
My Editor: rishu.rsing...
Intro Sequence: We have bought all the required Licenses of the Audio, Video & Animation used.
Timestamps:
00:00 - Introduction to Heaps & CBT
07:06 - Promotion
07:57 - Max-Heap or Min-Heap
09:37 - Insertion in heap
15:45 - Heap Class Implementation
16:20 - Insertion Code
21:48 - Deletion in Heap
25:25 - Deletion Code
31:00 - Heapify Algorithm
38:30 - Heapify Code
48:55 - Heap Sort
56:00 - Heap Sort Code
59:33 - Priority Queue
#DSABusted #LoveBabbar
Пікірлер: 808
in deletion there should one condition should also mention arr[leftIndex]
@naveensingh4859
Жыл бұрын
yepp,this code is right bro
@aadilkhan4867
Жыл бұрын
thanks a lot you too bhaiya
@PratikD-dy4yo
Жыл бұрын
exactly.... !
@anshikajain3298
Жыл бұрын
if you use if statements only instead of if and else if then you will get the correct answer
@ekanshsharma1309
Жыл бұрын
Thank you buddy :)
Hey bhagwan jii babbar bhaiya jesa dedication aur consistency dedo apne goal ke liye 👌🙏🔥
@AmanKumar-ec6bz
2 жыл бұрын
Self motivated rkho then all goals you achieve 🤞
@awwtanu
Жыл бұрын
Ekdum bro
@iitmotivationwithrahullson5930
Жыл бұрын
Milegii bhi😀
@cs_111_amansingh6
Жыл бұрын
Ye bhai tumne dil ki baat chhin li
@VivekVerma-oo3dx
5 ай бұрын
nazar lagadi tum logo ne ab video hi ni dalpate bhaia😂
I think there will be one more condition in deletion for checking that if left is also greater than right or if right is greater than left in else if. One more thing when we are checking the bound in that it should be less than equal to. The correct code for deletion will be void deletefromHeap() { if(size==0) { cout
@user-xy6vx6mn9q
7 ай бұрын
leftIndex
@ruchikabihari9980
7 ай бұрын
I do agree 👍👍
@deveshgupta2931
6 ай бұрын
Bcoz without equal sign we will miss the last child bcoz we have already decremented the size above in the code @@user-xy6vx6mn9q
@deveshgupta2931
6 ай бұрын
One more correction when we are checking leftindex
@deepakbanga5166
5 ай бұрын
Even this is not going to work in case of example :- 10 7 6 5 2
attendance ++ aandd consistency ++,aur bahot mazha araha hai,completed 160 questions on leetcode since january 1
I have started advanced dsa so many times from different sources and channels but this time the understanding is of next level thanks a lot bhaiya
Eagerly waiting for this!!! Thank you so much Bhaiya for covering this topic ♥️💯💯
The best explanation of heaps out here in C++. Such great content !!!
I never enjoyed coding ...but after following your course ..now icoding becomes my habit .thanks a lot bhaia
25:02 Deletion logic me you swapped with whichever of the two children are greater. 28:30 Code: compares with either left or, later, right. If left one is greater (even if not greater than right) then that case will run. Suppose tree was 52 53 54 50, then code would make it 53 52 54 50 and not 54 53 52 50. Koi baat nhi hume logic samajh aa gya👍
@Ranjankumar-ik4vf
Жыл бұрын
Yes
@abhibitcodes
Жыл бұрын
yes
@sudhanshusingh2579
Жыл бұрын
for the second one , dono me if statements use hue hai, so agar pehla wala true hota hai, to pehla wala largest hoga, uske baad wo dusre wale k saath pehla compare hoga because wo already largest ho chuka hai,
@MDAKMAL0786
Жыл бұрын
*DELETION CORRECT CODE WITH EACH EDGE CASE void dlt () { if ( size == -1 ) { cout
@tusharvlogs6333
Жыл бұрын
ye jo tree hai 52 53 54 50,, ---> ye kisi heap property ko follow hae nahi krrha nither minheap nor maxheap toh isko pehle ek heap property ka tree banao, scondly haan there is error in thr code for deletion. we need to compare leftchild and rightchild before saying who is the greatest of them
Itna achy sy Heap ko sari youtube py kisi ny nahi samjhaya...You are great Sir. Thanks for this amazing series.
thank you for being so great with us, you have clarified the searching technique of parent, left and right node so easily.
the way you explain things is great because you cover all the details in your lecture.
I think #LoveBabbar did a slight mistake while writing the deletion method. We should do some slight modification in that code... void deleteRoot(){ if(size==0){ cout
@saptarshimajumdar180
11 ай бұрын
i was also stuck at this
@user-mf8qt2by9i
11 ай бұрын
Thanks u r the saviour
@UwUDibboChowdhury
11 ай бұрын
thank you later . uwuw
@cheems08213
11 ай бұрын
still wrong, in modification 1's if condition you are accessing arr[rightInd] without checking rightIndex
@sumitworld918
10 ай бұрын
Literally you save my time, thanks❤❤
It seems there is an issue in the deletion function. It is only checking either the left or right child, whereas it should check both the left and right children, similar to how it's done in the heapify function.
@SreevalliB-zv7qy
4 ай бұрын
yess!
la jawab! simply magnificent! boht hi nazakat se ek jattil vishya ko suljhaya!
correction in the deletion method - compare the leftIndex and rightIndex, then swap the greater one if it is greater than parent.
@ankitkumar-ri2oh
Жыл бұрын
correct bro
@suratnu4609
Жыл бұрын
can u pls send me the correct code
@rajeevkumaryadav6948
Жыл бұрын
@@suratnu4609 void deleteFromHeap(){ if(size==0){ cout
@ashhariqbalshanu
Жыл бұрын
@@rajeevkumaryadav6948 // Simpler one void deleteh() { if (size == 0) { cout
@ShivkumarRajmane
5 ай бұрын
@@ashhariqbalshanu thanks for help bro
Awesome Explanation sir ji.. No one has covered these advanced topics so bautifully.😇
I can't thank you enough bhaiya for this amazing series.. this series is helping me a lot to polish my skills. You are a great teacher and blessing to us ⭐
The BEST explanation of heaps on the internet, Great video
consistency again high hai bhaiya dono ki.........thanks.
Love you babbar bhai....... Ham Garibo ke liye IT MEANS ALOT
Right now I am watching your 74th lecture , Tq for this course Bhaiya 🤘
Best video for understanding heaps. Thank you so much!
One of the Best lecture on Heap Topic .ThankYou Bhaiya 🙂
it feels good to continue watching the whole series and completed this many lectures thank you bhaiya for providing us this amazing series free of cost.
@vidhijaiswal1939
Жыл бұрын
Are you able to solve leetcode questions?
Welcome back bhaiya with great consistency
I never enjoyed coding ...but after following your course ..now icoding becomes my habit .thanks a lot bhaia #love babbar
wahh bhiyaa mza aa gya ekdum jabardast...subkuch samaj aya mereko......thanks bhiya love u
I love you babbar bhaiyya... doing heap revision and still everything is crystal clear...
present marked sir ,getting motivation from your consistency level, aag laga diye bhaiya aap..
Best DSA playlist ever, thank you so much for helping us.😍😍❤❤
really , i have watched almost all the available videos on heap but you explained everything about heap and in great way , thankyou for this effort
@amnashahzadi7608
10 ай бұрын
is heap structure is created only using arrays ? no need to create nodes like in tree ?
In deletion , we are not firstly comparing left and right child to find which is max ,we are simply uisng if else, if left greater than a[i] , we are swaping a[i] with left and due to if else , we are not comparing a[i] with right child , so little confusion in deletion code
@businessburstx
2 жыл бұрын
yes its not right you run for other test case. use heapify function instead to put new root at right position'
@AjayYadav-um1oj
2 жыл бұрын
@@KazHachiOreki You are wrong bro there is problem in deletion : After deleting first element if parent is 30 leftchild 40 rightchild 50 and according to code we are swapping with leftchild then parent 40 leftchild 30 rightchild still 50 (here rightchild is greater than parent which is not a heap) so we have to take max of left and right child before swapping ; please clarify if i am wrong ;
@abhijithkannan850
Жыл бұрын
yes to my understanding the parent node should swap the largest value among left and right child. Thus a comparison b/w left and right child value is necessary
Maza aagya bhaiya... Thanks to this course... Ab contest me bhi questions solve ho rhe hai... 3 months pehle he coding seekhni start ki thi aapke saath... Thanks again !!!!!❤❤❤❤
Great explanation and the best part is your approach towards the question, it really helped me, thanks a lot bhaiya.
Babbar bhai thanks a lot. Mujhe kabhi nahi laga tha mai array k alawa kuch samajh bhi sakunga but after watching your videos I can't believe I have started solving Hard level DSA questions on leetcode. Thank you so much brother.
bahut shi lecture full knowledge ...........great Content
Best DSA course on youtube !!👍
You guys are the ones, for whom we cse students can survive.
THANKYOU SO MUCH BHAIYA FOR THE AWESOME VIDEOS,SAB SMZH AA GYA Attendance ++ and Consistency ++
Thanks for explaining such typicall topic in such a easy way...🤩🤩
One of the finest explanations. May God bless you.
Mja hi aa gya bhaiya aap se heap topic pdke... Thanks, bhaiya for making such an amazing course
your content and explanation just awesome bhaiya. Some guys just notice one mistake and keep barking abt that without knowing how much effort you put for one lecture
even after 6 months no had made Data Structure course like yours Babbar bhaiya.
Attendance marked ... Thank you so much for this course
thanq thanq thanq bhaiyaa .. majja agya isme toh .. kamaal krte ho aap..
I think there's a mistake in Heapify Algorithm, the right condition should be right
@AtulSharma-sr9wi
Жыл бұрын
index is start from 0 so given ans is correct.
@KKK-bn3ez
Жыл бұрын
yes. I just discovered it myself also. Glad to see someone also been practicing and finding errors also.
@PRITESHKRSRV
Жыл бұрын
@@AtulSharma-sr9wi starting index is taken 1 from the beginning of the video, were u on weeds while taking the lecture ?
@PRITESHKRSRV
Жыл бұрын
Thanks for pointing out bro
probably the best course for dsa in youtube thanks a lot bhaiya
I learned all topic from start this dsa course very help full beginner level to high level because small concet point to point understand by love babbar bhaiya so again thanks bhaiya for free course . this best explanation for heap topc in c++.
I don't have words to express about ur dedication & hardworking. Tusi great ho great babar bhaiya
Lecture was superb dear Thanks a lot for such amazing content!
Best video for understanding heaps. Thank you so much
Thank you Bhaiya 🙏 aisa course dene ke liye, ab lagta hai kuch kar sakta hai aapn log.
Hey everyone, just wanted to point out a small mistake in the code demonstrated in the tutorial. In the heapify function, when checking the conditions for left and right children, it should be leftchild
bhaiya... 1 saal baad is video dekhne aaya hoon.. kuki bhul gya hoon heapify function But ye wala look me aapko firse dekh ke maza aagya sachi bata rha hoon 😅😍😍
tagda video , everything explainded very clearly with clear logic and code .
Ek no. bhiya we dont want animation but the quality content.....my concept getting stronger day by day....i will watch more 2 videos of heap question and please upload hash in upcoming week so that i can study that topic.
Thanks brothers , Our bangladeshi Coders really depends on the guys like you
Awesome video Bhaiya. Thanks!
present sir.. great course all credit to you
Thanks brother love your dedication and hard work.
A like is not enough justify the efforts and quality of this video. Thanks.
Thanks Bhaiya for this wonderful course ❤
The way you teach is unstoppable. you are amazing teacher💯💯❤🔥❤🔥❤🔥
thanks luv babbar 💛 couldnt find any better way to understand heaps than this , respect++
great video bhaiya!!
Thank you Bhaiya for your consistency ❤❤❤
bhaiya badhiya lga hain.....
Best video for understanding heaps.
29:16 it's better to keep leftIndex
@SreevalliB-zv7qy
4 ай бұрын
yes, actually. I don't understand why he's isn't checking those cases. He wrote it wrong?
kya baat hai bhaiya, concept ++;
Much needed one 🔥
thank you so much sir, for making this topic easily understandable
Lovely DSA series by babbar bhaiya
Best course for DSA Thanku bhaiya
Hats off to dedication level of bhaiya for us.
Keep going bhaiya. You are doing a great job 👍
Indeed a great lecture! a great Playlist!
Thanks for good content bhaiyaa 👍
while(codehelp==babbar){ learning ++; cout
thanku so much for providing such amazing video 🙏🙏
Maja aa raha hai bhaiya course me 🔥❤️
hats off to your consistency
Mja a gya ......such an elaborative and simple explanation
gajab hi video h bhai
I think there is an error in the deletion part. We are first checking the left then right. But what if right part is maximum? Try making a heap this way and you'll understand: 50 55 54 53 53 upon deletion, we get : 53 52 54 50: 53 becomes root and 54 comes later...
@ashutosh7944
6 ай бұрын
there is no problem in sir code it is 100% correct listen if there is no need to swap in left then we swap in right side then this means we have to forget the left subtree for further sorting because there is no need and vice versa and this continues until all conditions fulfilled and then return if you dry run you will notice this:) believe me just dry run
@dipjain8679
6 ай бұрын
there is a problem,take example as 52 53 54 50 you will get wrong answer as:53 52 54 50@@ashutosh7944
@RidamMittal
6 ай бұрын
ya you are right its wrong and incomplete
Really great consistency hai sir aapki I'm not able to match till now even🌚
Maja aa gaya bhiya stay consisted bhaiya 🙂
Maja aagya bhai very informative
Clear as crystal bhaiya
You know you are beauty with brains!!
Attendence Marked Bhaiya...Up to dated m, And enjoying every lectures till now,,Thanks A Lot....
you are the best teacher Bhaiya ,Really Your video is awesome
Great Lecture Sir...
thank you bhaiya,going strong
Babber bhaiya flexing with his glasses👓😂
sir , i'm from bangladesh. i like your all videos. i'm following DSF playlist . thank you for making this awesome video
Thank You so much for sharing the video!