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

  • @chiragyadav5467
    @chiragyadav5467 Жыл бұрын

    in deletion there should one condition should also mention arr[leftIndex]

  • @naveensingh4859

    @naveensingh4859

    Жыл бұрын

    yepp,this code is right bro

  • @aadilkhan4867

    @aadilkhan4867

    Жыл бұрын

    thanks a lot you too bhaiya

  • @PratikD-dy4yo

    @PratikD-dy4yo

    Жыл бұрын

    exactly.... !

  • @anshikajain3298

    @anshikajain3298

    Жыл бұрын

    if you use if statements only instead of if and else if then you will get the correct answer

  • @ekanshsharma1309

    @ekanshsharma1309

    Жыл бұрын

    Thank you buddy :)

  • @unboxtheuniverse5336
    @unboxtheuniverse53362 жыл бұрын

    Hey bhagwan jii babbar bhaiya jesa dedication aur consistency dedo apne goal ke liye 👌🙏🔥

  • @AmanKumar-ec6bz

    @AmanKumar-ec6bz

    2 жыл бұрын

    Self motivated rkho then all goals you achieve 🤞

  • @awwtanu

    @awwtanu

    Жыл бұрын

    Ekdum bro

  • @iitmotivationwithrahullson5930

    @iitmotivationwithrahullson5930

    Жыл бұрын

    Milegii bhi😀

  • @cs_111_amansingh6

    @cs_111_amansingh6

    Жыл бұрын

    Ye bhai tumne dil ki baat chhin li

  • @VivekVerma-oo3dx

    @VivekVerma-oo3dx

    5 ай бұрын

    nazar lagadi tum logo ne ab video hi ni dalpate bhaia😂

  • @rahulpanjwani8449
    @rahulpanjwani8449 Жыл бұрын

    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

    @user-xy6vx6mn9q

    7 ай бұрын

    leftIndex

  • @ruchikabihari9980

    @ruchikabihari9980

    7 ай бұрын

    I do agree 👍👍

  • @deveshgupta2931

    @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

    @deveshgupta2931

    6 ай бұрын

    One more correction when we are checking leftindex

  • @deepakbanga5166

    @deepakbanga5166

    5 ай бұрын

    Even this is not going to work in case of example :- 10 7 6 5 2

  • @anuragraut5101
    @anuragraut51012 жыл бұрын

    attendance ++ aandd consistency ++,aur bahot mazha araha hai,completed 160 questions on leetcode since january 1

  • @garvitchaurasiya2041
    @garvitchaurasiya2041 Жыл бұрын

    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

  • @aishwaryaporwal2321
    @aishwaryaporwal23212 жыл бұрын

    Eagerly waiting for this!!! Thank you so much Bhaiya for covering this topic ♥️💯💯

  • @tribikramdhar2811
    @tribikramdhar2811 Жыл бұрын

    The best explanation of heaps out here in C++. Such great content !!!

  • @ritiksharma-im6dx
    @ritiksharma-im6dx Жыл бұрын

    I never enjoyed coding ...but after following your course ..now icoding becomes my habit .thanks a lot bhaia

  • @piyushtiwari6471
    @piyushtiwari6471 Жыл бұрын

    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

    @Ranjankumar-ik4vf

    Жыл бұрын

    Yes

  • @abhibitcodes

    @abhibitcodes

    Жыл бұрын

    yes

  • @sudhanshusingh2579

    @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

    @MDAKMAL0786

    Жыл бұрын

    *DELETION CORRECT CODE WITH EACH EDGE CASE void dlt () { if ( size == -1 ) { cout

  • @tusharvlogs6333

    @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

  • @ghauriaja3768
    @ghauriaja3768 Жыл бұрын

    Itna achy sy Heap ko sari youtube py kisi ny nahi samjhaya...You are great Sir. Thanks for this amazing series.

  • @aarti263
    @aarti2632 жыл бұрын

    thank you for being so great with us, you have clarified the searching technique of parent, left and right node so easily.

  • @naeembrohi1821
    @naeembrohi18212 жыл бұрын

    the way you explain things is great because you cover all the details in your lecture.

  • @debajyatibanerjee5480
    @debajyatibanerjee5480 Жыл бұрын

    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

    @saptarshimajumdar180

    11 ай бұрын

    i was also stuck at this

  • @user-mf8qt2by9i

    @user-mf8qt2by9i

    11 ай бұрын

    Thanks u r the saviour

  • @UwUDibboChowdhury

    @UwUDibboChowdhury

    11 ай бұрын

    thank you later . uwuw

  • @cheems08213

    @cheems08213

    11 ай бұрын

    still wrong, in modification 1's if condition you are accessing arr[rightInd] without checking rightIndex

  • @sumitworld918

    @sumitworld918

    10 ай бұрын

    Literally you save my time, thanks❤❤

  • @narendramohanpathak4456
    @narendramohanpathak44564 ай бұрын

    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

    @SreevalliB-zv7qy

    4 ай бұрын

    yess!

  • @hardycollins8917
    @hardycollins8917 Жыл бұрын

    la jawab! simply magnificent! boht hi nazakat se ek jattil vishya ko suljhaya!

  • @faizanhussain4471
    @faizanhussain4471 Жыл бұрын

    correction in the deletion method - compare the leftIndex and rightIndex, then swap the greater one if it is greater than parent.

  • @ankitkumar-ri2oh

    @ankitkumar-ri2oh

    Жыл бұрын

    correct bro

  • @suratnu4609

    @suratnu4609

    Жыл бұрын

    can u pls send me the correct code

  • @rajeevkumaryadav6948

    @rajeevkumaryadav6948

    Жыл бұрын

    @@suratnu4609 void deleteFromHeap(){ if(size==0){ cout

  • @ashhariqbalshanu

    @ashhariqbalshanu

    Жыл бұрын

    @@rajeevkumaryadav6948 // Simpler one void deleteh() { if (size == 0) { cout

  • @ShivkumarRajmane

    @ShivkumarRajmane

    5 ай бұрын

    @@ashhariqbalshanu thanks for help bro

  • @shivanshuamitabh831
    @shivanshuamitabh8312 жыл бұрын

    Awesome Explanation sir ji.. No one has covered these advanced topics so bautifully.😇

  • @bhawargujral3574
    @bhawargujral3574 Жыл бұрын

    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 ⭐

  • @sparshverma5995
    @sparshverma59952 жыл бұрын

    The BEST explanation of heaps on the internet, Great video

  • @parthsharma5966
    @parthsharma59662 жыл бұрын

    consistency again high hai bhaiya dono ki.........thanks.

  • @krishnaradhey2814
    @krishnaradhey28142 жыл бұрын

    Love you babbar bhai....... Ham Garibo ke liye IT MEANS ALOT

  • @rakshitsindhwani8871
    @rakshitsindhwani88712 жыл бұрын

    Right now I am watching your 74th lecture , Tq for this course Bhaiya 🤘

  • @AAnand-my1ql
    @AAnand-my1ql2 жыл бұрын

    Best video for understanding heaps. Thank you so much!

  • @sportsclub725
    @sportsclub725 Жыл бұрын

    One of the Best lecture on Heap Topic .ThankYou Bhaiya 🙂

  • @sumitmishra3514
    @sumitmishra3514 Жыл бұрын

    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

    @vidhijaiswal1939

    Жыл бұрын

    Are you able to solve leetcode questions?

  • @yogeshsharma24
    @yogeshsharma242 жыл бұрын

    Welcome back bhaiya with great consistency

  • @CSEStudent777
    @CSEStudent777 Жыл бұрын

    I never enjoyed coding ...but after following your course ..now icoding becomes my habit .thanks a lot bhaia #love babbar

  • @prashantbirajdar9271
    @prashantbirajdar92712 жыл бұрын

    wahh bhiyaa mza aa gya ekdum jabardast...subkuch samaj aya mereko......thanks bhiya love u

  • @fgh427
    @fgh427 Жыл бұрын

    I love you babbar bhaiyya... doing heap revision and still everything is crystal clear...

  • @ehtemamulhaque8713
    @ehtemamulhaque87132 жыл бұрын

    present marked sir ,getting motivation from your consistency level, aag laga diye bhaiya aap..

  • @janvisharma2377
    @janvisharma23773 ай бұрын

    Best DSA playlist ever, thank you so much for helping us.😍😍❤❤

  • @nishanttrivedi8711
    @nishanttrivedi8711 Жыл бұрын

    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

    @amnashahzadi7608

    10 ай бұрын

    is heap structure is created only using arrays ? no need to create nodes like in tree ?

  • @codingaid2753
    @codingaid27532 жыл бұрын

    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

    @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

    @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

    @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

  • @utkarshsingh1457
    @utkarshsingh14572 жыл бұрын

    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 !!!!!❤❤❤❤

  • @rishabhkesarwani9506
    @rishabhkesarwani95062 жыл бұрын

    Great explanation and the best part is your approach towards the question, it really helped me, thanks a lot bhaiya.

  • @HARRY-xz1hf
    @HARRY-xz1hf Жыл бұрын

    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.

  • @Ayush_.
    @Ayush_.2 жыл бұрын

    bahut shi lecture full knowledge ...........great Content

  • @digvijayjadhav1452
    @digvijayjadhav1452 Жыл бұрын

    Best DSA course on youtube !!👍

  • @SupriyoGhosh-gz3fs
    @SupriyoGhosh-gz3fs2 ай бұрын

    You guys are the ones, for whom we cse students can survive.

  • @kunal4710
    @kunal47102 жыл бұрын

    THANKYOU SO MUCH BHAIYA FOR THE AWESOME VIDEOS,SAB SMZH AA GYA Attendance ++ and Consistency ++

  • @adarshtapariya4275
    @adarshtapariya4275 Жыл бұрын

    Thanks for explaining such typicall topic in such a easy way...🤩🤩

  • @ahmedsohail8923
    @ahmedsohail89238 ай бұрын

    One of the finest explanations. May God bless you.

  • @RohitRana-tz2lr
    @RohitRana-tz2lr2 жыл бұрын

    Mja hi aa gya bhaiya aap se heap topic pdke... Thanks, bhaiya for making such an amazing course

  • @venkateshpk7822
    @venkateshpk78222 ай бұрын

    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

  • @kishanprajapati3327
    @kishanprajapati3327 Жыл бұрын

    even after 6 months no had made Data Structure course like yours Babbar bhaiya.

  • @prathmeshparteki1016
    @prathmeshparteki10162 жыл бұрын

    Attendance marked ... Thank you so much for this course

  • @aaravkumar1308
    @aaravkumar13082 жыл бұрын

    thanq thanq thanq bhaiyaa .. majja agya isme toh .. kamaal krte ho aap..

  • @yashshetty7326
    @yashshetty7326 Жыл бұрын

    I think there's a mistake in Heapify Algorithm, the right condition should be right

  • @AtulSharma-sr9wi

    @AtulSharma-sr9wi

    Жыл бұрын

    index is start from 0 so given ans is correct.

  • @KKK-bn3ez

    @KKK-bn3ez

    Жыл бұрын

    yes. I just discovered it myself also. Glad to see someone also been practicing and finding errors also.

  • @PRITESHKRSRV

    @PRITESHKRSRV

    Жыл бұрын

    @@AtulSharma-sr9wi starting index is taken 1 from the beginning of the video, were u on weeds while taking the lecture ?

  • @PRITESHKRSRV

    @PRITESHKRSRV

    Жыл бұрын

    Thanks for pointing out bro

  • @sanchitsharma8413
    @sanchitsharma8413 Жыл бұрын

    probably the best course for dsa in youtube thanks a lot bhaiya

  • @pushpendrasharma1744
    @pushpendrasharma174411 ай бұрын

    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++.

  • @DPCODE72
    @DPCODE72 Жыл бұрын

    I don't have words to express about ur dedication & hardworking. Tusi great ho great babar bhaiya

  • @muhammadsuleman8936
    @muhammadsuleman893610 ай бұрын

    Lecture was superb dear Thanks a lot for such amazing content!

  • @AAnand-my1ql
    @AAnand-my1ql2 жыл бұрын

    Best video for understanding heaps. Thank you so much

  • @adarshparitosh5870
    @adarshparitosh58702 жыл бұрын

    Thank you Bhaiya 🙏 aisa course dene ke liye, ab lagta hai kuch kar sakta hai aapn log.

  • @avishkarpatil5871
    @avishkarpatil58714 ай бұрын

    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

  • @asifmondal7609
    @asifmondal760911 ай бұрын

    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 😅😍😍

  • @Aman-fz1ew
    @Aman-fz1ew Жыл бұрын

    tagda video , everything explainded very clearly with clear logic and code .

  • @Hidden..03
    @Hidden..032 жыл бұрын

    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.

  • @CNILOYBARUA
    @CNILOYBARUA Жыл бұрын

    Thanks brothers , Our bangladeshi Coders really depends on the guys like you

  • @AbhishekKumar-yu1mf
    @AbhishekKumar-yu1mf Жыл бұрын

    Awesome video Bhaiya. Thanks!

  • @prathmeshghate6404
    @prathmeshghate64042 жыл бұрын

    present sir.. great course all credit to you

  • @mayanksingh3171
    @mayanksingh3171 Жыл бұрын

    Thanks brother love your dedication and hard work.

  • @hardikshukla4508
    @hardikshukla4508 Жыл бұрын

    A like is not enough justify the efforts and quality of this video. Thanks.

  • @sahilhans1867
    @sahilhans1867 Жыл бұрын

    Thanks Bhaiya for this wonderful course ❤

  • @Its_._aayush
    @Its_._aayush11 ай бұрын

    The way you teach is unstoppable. you are amazing teacher💯💯❤‍🔥❤‍🔥❤‍🔥

  • @cyro_-ej6xm
    @cyro_-ej6xm2 ай бұрын

    thanks luv babbar 💛 couldnt find any better way to understand heaps than this , respect++

  • @Sam-rz5hw
    @Sam-rz5hw Жыл бұрын

    great video bhaiya!!

  • @TechnoBiz
    @TechnoBiz2 жыл бұрын

    Thank you Bhaiya for your consistency ❤❤❤

  • @MukeshKumar-fz3sw
    @MukeshKumar-fz3sw Жыл бұрын

    bhaiya badhiya lga hain.....

  • @ujjwalpratap8729
    @ujjwalpratap87292 жыл бұрын

    Best video for understanding heaps.

  • @msabhinavchandra4174
    @msabhinavchandra41745 ай бұрын

    29:16 it's better to keep leftIndex

  • @SreevalliB-zv7qy

    @SreevalliB-zv7qy

    4 ай бұрын

    yes, actually. I don't understand why he's isn't checking those cases. He wrote it wrong?

  • @sahilchhabra2391
    @sahilchhabra2391 Жыл бұрын

    kya baat hai bhaiya, concept ++;

  • @kumarpawansahh
    @kumarpawansahh2 жыл бұрын

    Much needed one 🔥

  • @sahilsandi07
    @sahilsandi07 Жыл бұрын

    thank you so much sir, for making this topic easily understandable

  • @abhishekpandey8514
    @abhishekpandey85146 ай бұрын

    Lovely DSA series by babbar bhaiya

  • @yashgupta4866
    @yashgupta48662 жыл бұрын

    Best course for DSA Thanku bhaiya

  • @KaustubhPathak9
    @KaustubhPathak9 Жыл бұрын

    Hats off to dedication level of bhaiya for us.

  • @coderrr3353
    @coderrr3353 Жыл бұрын

    Keep going bhaiya. You are doing a great job 👍

  • @amishapandey6875
    @amishapandey6875 Жыл бұрын

    Indeed a great lecture! a great Playlist!

  • @RajSingh-bb5uj
    @RajSingh-bb5uj2 жыл бұрын

    Thanks for good content bhaiyaa 👍

  • @ajaybabupatel1665
    @ajaybabupatel1665 Жыл бұрын

    while(codehelp==babbar){ learning ++; cout

  • @smartcoding174
    @smartcoding1742 жыл бұрын

    thanku so much for providing such amazing video 🙏🙏

  • @anuptewary3016
    @anuptewary30162 жыл бұрын

    Maja aa raha hai bhaiya course me 🔥❤️

  • @kumarshubham4327
    @kumarshubham4327 Жыл бұрын

    hats off to your consistency

  • @vipulkumar947
    @vipulkumar947 Жыл бұрын

    Mja a gya ......such an elaborative and simple explanation

  • @amritanshkaushik6823
    @amritanshkaushik6823 Жыл бұрын

    gajab hi video h bhai

  • @balvindersingh339
    @balvindersingh3396 ай бұрын

    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

    @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

    @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

    @RidamMittal

    6 ай бұрын

    ya you are right its wrong and incomplete

  • @bishnoibajrang
    @bishnoibajrang Жыл бұрын

    Really great consistency hai sir aapki I'm not able to match till now even🌚

  • @veetmoradiya4947
    @veetmoradiya49472 жыл бұрын

    Maja aa gaya bhiya stay consisted bhaiya 🙂

  • @AmrutanshuMishra-dp1mf
    @AmrutanshuMishra-dp1mf8 ай бұрын

    Maja aagya bhai very informative

  • @yashharode5700
    @yashharode5700 Жыл бұрын

    Clear as crystal bhaiya

  • @Ma.keITEasy
    @Ma.keITEasy9 ай бұрын

    You know you are beauty with brains!!

  • @rajasinghrajpoot8626
    @rajasinghrajpoot86262 жыл бұрын

    Attendence Marked Bhaiya...Up to dated m, And enjoying every lectures till now,,Thanks A Lot....

  • @amritranjan2802
    @amritranjan2802 Жыл бұрын

    you are the best teacher Bhaiya ,Really Your video is awesome

  • @m.baliramgupta
    @m.baliramgupta9 күн бұрын

    Great Lecture Sir...

  • @kshitizmayank7208
    @kshitizmayank72085 ай бұрын

    thank you bhaiya,going strong

  • @anchalbhardwaj7387
    @anchalbhardwaj73875 ай бұрын

    Babber bhaiya flexing with his glasses👓😂

  • @trying-code3726
    @trying-code3726 Жыл бұрын

    sir , i'm from bangladesh. i like your all videos. i'm following DSF playlist . thank you for making this awesome video

  • @risavkumarjha6899
    @risavkumarjha68993 ай бұрын

    Thank You so much for sharing the video!