7.9 Heap Sort | Heapify Method | Build Max Heap Algorithm | Sorting Algorithms

Поділитися
Вставка
  • Опубліковано 28 гру 2024

КОМЕНТАРІ •

  • @JennyslecturesCSIT
    @JennyslecturesCSIT  2 роки тому +221

    CORRECTION: at 42:50 heapify call for delete logic would be maxheapify(A, i-1,1) and in maxheapify method instead of while loop we can write if statement. :)

    • @alexmercerind
      @alexmercerind 2 роки тому +6

      Thanks!

    • @-Corvo_Attano
      @-Corvo_Attano 2 роки тому +4

      👍

    • @himanshukushwaha5064
      @himanshukushwaha5064 2 роки тому +1

      👍

    • @sankhadip_roy
      @sankhadip_roy 2 роки тому +1

      After correction also sorted output in not coming !
      -----------------------------------------------------
      #include
      void printArray(int *A, int n)
      {
      for (int i = 0; i < n; i++)
      {
      printf("%d ", A[i]);
      }
      printf("
      ");
      }
      void swap(int *A, int i, int j)
      {
      int temp;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
      }
      void maxHeapify(int *A, int n, int i)
      {
      int largest = i;
      int l = (2 * i);
      int r = (2 * i) + 1;
      if (l A[largest])
      {
      largest = l;
      }
      if (l A[largest])
      {
      largest = r;
      }
      if (largest != i)
      {
      swap(A, largest, i);
      maxHeapify(A, n, largest);
      }
      }
      void heapSort(int *A, int n)
      {
      {
      int temp;
      for (int i = n / 2; i >= 1; i--) // build max heap
      {
      maxHeapify(A, n, i);
      }
      for (int i = n; i >= 1; i--) // deleting
      {
      swap(A, 1, i);
      maxHeapify(A, i - 1, 1);
      }
      }
      }
      int main(void)
      {
      int A[] = {4, 6, 1, 2, 45, 12, 40};
      int n = 7;
      printArray(A, n);
      heapSort(A, n);
      printArray(A, n);
      return 0;
      }

    • @ssr9589
      @ssr9589 Рік тому +13

      I came here to tell this. I have been trying to solve this problem for 3 hours.
      Anyway, thank you.

  • @sameekasaini473
    @sameekasaini473 2 роки тому +182

    The beauty of these lectures is that even faculty learns from here to teach their students....you are amazing mam....

  • @AdityaKumar-fz8oi
    @AdityaKumar-fz8oi 4 роки тому +1370

    So basically we're all going to university to get our degree but we learn all the stuff from youtube tutorials.

    • @JustinK0
      @JustinK0 3 роки тому +37

      yep and always from a smart person from india, but at least this woman is beautiful!

    • @satyabansahoo1862
      @satyabansahoo1862 3 роки тому +22

      Yeah welcome to understanding India's Education System

    • @tungtruong5904
      @tungtruong5904 3 роки тому +6

      true, university is just an outline :D

    • @mistryhitenbharatkumar36
      @mistryhitenbharatkumar36 3 роки тому +7

      @@tungtruong5904 true said bro college sirf namki he lekin sab log asli padhai youtube parshe hi karte

    • @sindisss3897
      @sindisss3897 3 роки тому +14

      ive watched so many indian youtube tutorials , ima get hindi degree till end of college

  • @codeisawesome369
    @codeisawesome369 5 років тому +225

    I’ve subscribed and turned on notifications and you didn’t even have to ask for it. That’s the mark of a quality uploader. Thank you for sharing your valuable knowledge.

  • @UnnaipolOruvan007
    @UnnaipolOruvan007 5 років тому +70

    First I watched your CountingSort video...then didn’t stop watching your other videos. Thats the quality of your videos. This generation students are very lucky to have open university and talented lecturer like you in youtube. In reality all the students wont get best teacher in their classrooms. Kudos to your work, keep doing 🙏, I read so many program sites couldn’t explain clearly like you explain the example with all the iteration passes. Doing 1 or 2 iteration passes will not give deep understanding of the solution. 🙌🏻

  • @rutwickgangurde3247
    @rutwickgangurde3247 4 роки тому +6

    Also I for the life of me could not understand why to take n/2 as the starting point, while looking at a piece of code for Heap sort. You explained that critical bit of info with a use case. Thank you!

  • @JyotiSharma-wb1vy
    @JyotiSharma-wb1vy 2 роки тому +15

    No other person can explain these algorithms better than Jenny Mam. Everything is explained beautifully with pictorial representation as well as with code. Thanks a lot Mam!

  • @nayanachandran7072
    @nayanachandran7072 Рік тому +2

    Excellent video. The concept of heap sort and heapify is easy to understand but the code can be a little complex to come up with. I tried for 3 hours and watched numerous videos and stumbled upon this gem. You earned a follower! Thank you so much!

  • @shubham-pp4cw
    @shubham-pp4cw 4 роки тому +3

    Explantation is excellent and simplified way.
    At (42 min)in delete method looping should start with (i=n-1) if its start with n it will give one garbage value in array

  • @soumyajitdas1262
    @soumyajitdas1262 4 роки тому +21

    Thanks mam. Passed my 3 semesters by watching your videos. 🙏♥️

  • @amarverma3423
    @amarverma3423 2 роки тому +3

    You are only in UA-cam who explained this algorithm in structured and easy way.👍

  • @AnimeManiaa
    @AnimeManiaa 5 років тому +13

    Actually i want to give as many as likes possible for your lecture but here he gave only one.....😍😍

  • @shakalyatech
    @shakalyatech Рік тому +9

    Most valuable gem of IT and data Science : Jenny Ma'am 😊

  • @pradeexsu
    @pradeexsu 5 років тому +2

    Thank u mam for that grt video.
    Aap hi ho meri real DSA waali mam.
    My dsa marks credit goes to you only.
    Love you mam

  • @shajahanshaik9206
    @shajahanshaik9206 Рік тому +1

    Paying lakhs in the college and these UA-cam videos are more helpful than my entire life

  • @dhruvkaran9724
    @dhruvkaran9724 5 років тому +6

    mam u taught like god...
    each concept is now embedded in me.

  • @StAnDUp1438
    @StAnDUp1438 3 місяці тому

    Always wearing a watch is often seen as a symbol of responsibility, punctuality, and attention to detail.I love it mam.

  • @vasan65
    @vasan65 4 роки тому +19

    Thank you, I really appreciate the fact that you are taking the time to do these videos, which is really good quality, top information regarding algorithms. You are an amazing teacher, I am sure you put in loads of hard work to come up with a method and solution which is easy to understand.

  • @thedreams4518
    @thedreams4518 4 роки тому +126

    My university lecturer play your video in class and teach us algorithms 😂❤

  • @tarifhingolaja5831
    @tarifhingolaja5831 3 роки тому

    First for all we are converting our array into heap using heapify method.
    In heapify the we are starting from none leaf node so we are eliminating leaf node therefore we have used i=n/2; and we passing parameter as I.
    And in other for loop we are going to sort the heap and here we going to use deleting root node method for sorting therefore we passed 1 instead of i.
    Thankyou Ma'am.
    You're teaching is very nice.🥰

  • @payalsagar1808
    @payalsagar1808 5 років тому +34

    I sometimes feel very happy that I m preparing for GATE2020😍😍really very clear explanation thankyou!

  • @MegaDoc360
    @MegaDoc360 8 місяців тому

    You really are one of the best teachers for data structures and algorithms.

  • @storylineonlinehamzashahid8368
    @storylineonlinehamzashahid8368 4 роки тому

    Mam Jinny Thank you sooo Much agaar ap na hoti tou data structure ka course parhana bhot mushkil Hota Huge respect for you mam .Luv From Pakistan

  • @kasoul_gaming
    @kasoul_gaming 4 роки тому +1

    Mam you r 100000 times better than my college mam..your presentation techniques is very pleasant..thank you mam to teach us in this way.❤

  • @a.jiteshsai-5012
    @a.jiteshsai-5012 4 роки тому +1

    My college professor and your explanation is very easy

  • @AvinashKumar-sx5ee
    @AvinashKumar-sx5ee Рік тому

    The last dry run has cleared my doubt. Mam you are gem for us.

  • @pyaephyothaw10107
    @pyaephyothaw10107 8 місяців тому

    i am leaning itpec and when i see your videos of all , more easy to learn and have a graet solutions for exam . i really really appreciate .

  • @saurabhdsawant
    @saurabhdsawant 4 роки тому

    It took me a long time to understand what she is saying ! Not because she is bad at explaining , I was just not able to hear anything once I saw her .
    Btw ! Thanks for the info . Keep it up.

  • @mr_justic3
    @mr_justic3 3 роки тому +3

    What a great explanation Jenny! Was thinking to skip heap sort thinking its 46 min explanation but actually worth it! Now I know heap sort from leaf to root xD

    • @tan9744
      @tan9744 2 роки тому +1

      Leaf to root XDDD

  • @himanshuyadav7327
    @himanshuyadav7327 4 роки тому +1

    Was preparing for the internship drive(interview season), wanted a heap & heapsort revision and here it is. Saved once again :)

    • @vishaldas5692
      @vishaldas5692 4 роки тому

      So how was your interview...??😬

    • @himanshuyadav7327
      @himanshuyadav7327 4 роки тому

      @@vishaldas5692 lol😂 I got internship 🙌😇

    • @vishaldas5692
      @vishaldas5692 4 роки тому +1

      @@himanshuyadav7327 Haha great u got on this covid situation....!!🥳

  • @ogananfe
    @ogananfe 2 роки тому +1

    Indians always have the best programming content

  • @tushartomar8664
    @tushartomar8664 2 роки тому

    One of the best teacher on you tube. Thanks mam for all your efforts u put for students and keep making such videos.

  • @saratchand4275
    @saratchand4275 4 роки тому

    Being a teacher,, you are good at your job... Let us enjoy and learn well... Fantastic..

  • @tarunmathur7797
    @tarunmathur7797 5 років тому +30

    27:26 will start from here for revision

  • @superfact4556
    @superfact4556 5 років тому +16

    Thanks for clearing my doubts
    ...ur teaching stye is unique

  • @aashish1809
    @aashish1809 5 років тому +61

    beauty with brain --- deadly combination

  • @saritakumari-oh8fs
    @saritakumari-oh8fs 4 роки тому

    Simplest logic explanation for complex function maxHeaify(). You are great Maam

  • @RahulGupta-go8oe
    @RahulGupta-go8oe 5 років тому +1

    mam ur voice is soothing to my ears, very pleasant to have u as a teacher.

  • @Fictional_universe
    @Fictional_universe 4 роки тому +1

    Hello api,, i am from Bangladesh..
    I have seen many videos about heapsort 😪😪but none of this could able to explain the algorithm as clearly+easily as you....😊😊
    You lecture just amazing💚💚💚 api❤❤ and very much helpful to me. I am very grateful to you. 🥰🥰
    Also expecting more lectures about data structure and algorithm from you..🥰😻😻😻💚💚

  • @memd777
    @memd777 3 роки тому +1

    "maxheapify method instead of while loop we can write if statement. :)"
    Glad you corrected this yourself, I was about to correct you there. But its ok because Approach is right, I understand it is difficult to code when not using an IDE.

  • @vickygill07
    @vickygill07 3 роки тому +14

    @Jenny's lectures CS/IT NET&JRF A small correction, in the logic of sorting loop, instead of maxHeap(A, i-1, 1) we have to use maxHeap(A, i-1, 0) because the index starts from 0 and our first element will always be at index 0.

    • @Local_Review
      @Local_Review 2 роки тому

      Here index 0 contains sentinel value bro so we start from index 1 only

  • @Mandeepsingh-jo5cf
    @Mandeepsingh-jo5cf 3 роки тому +2

    tremendous lecture on heap sort. Highly recomended.

  • @sriram8970
    @sriram8970 4 роки тому +1

    Wonderful teaching I am now just able to remember after listening only one time and cuteness overloaded

  • @gorintlavijayavalli5751
    @gorintlavijayavalli5751 3 роки тому +1

    U r awesome mam....... tomorrow I have a sem 3 ....iam super satisfied with ur explanation mam tq......

  • @akashvishwakarma1493
    @akashvishwakarma1493 4 роки тому +10

    I think
    In the deletion part the call to heapify must be like:
    MaxHeapify(A,i-1,1);
    As if we pass n after execution it will put 15 in last again and 30 in middle so tree would not be MaxHeap anymore.
    And seperate from it
    Thankyou for being such awesome teacher😇

  • @ilb3411
    @ilb3411 4 роки тому +11

    Jenny your lectures are such great help! I’m relieved to have found your channel! Thank you for being so thorough with your explanations :)

  • @sudhamoneyjayaprakash5704
    @sudhamoneyjayaprakash5704 3 роки тому

    that last part were you said it is heap sort....that was like magic..i was afraid of heap sort thought it was difficult but you explained it so magically

  • @tawseeftaher9109
    @tawseeftaher9109 Рік тому +4

    insert O(nlogn)
    delete O(nlogn)
    20:30 leaf node
    25:38 O(n)
    35:00 pseudocode of O(n) | heapify
    42:42 heap sort | O(nlogn)

  • @satishkarthik9058
    @satishkarthik9058 4 роки тому +1

    super mam you was mother of data structures

  • @shiladityapatra2896
    @shiladityapatra2896 2 роки тому +1

    you are a wonderful teacher. My whole DSA basic I clear from this channel. thanks mam. and request you to bring more content related to university subjects..
    😇🙂

  • @vipulpatel4800
    @vipulpatel4800 4 роки тому

    Your lectures are awesome, easy to understand and with every aspect covered. I am able to learn algorithms only because of your lectures.
    However, just wanted to point out a couple of really minor mistakes in the code and hence the logic.
    1. We need to call the swap method in MaxHeapify method within each of the while loops. If we have an array - 2|500|300, calling swap just once outside the while block will result in - 300|500|2 which is not a max heap.
    2. In our main HeapSort method, when we are doing the "deleting and building" logic, we need to call the MaxHeapify, written after the swap, as - MaxHeapify(Array, i-1, 1) i.e. instead of passing the entire length "n", we need "i-1".
    The reason is : i = n at the start of this loop. So after the very first swap, our last index is already a sorted array. Hence, we need not call the Maxheapify method on entire array. Instead, just call this method for the remaining elements.
    I hope this is clear enough. Thanks once again mam for posting these videos! :)

    • @ayushkwal
      @ayushkwal 3 роки тому

      Jyada angrezi nahi jhaadni chahiye

  • @akashsarkar1040
    @akashsarkar1040 Рік тому

    Didi your teaching procedure by English communication is A1 .. lv from west bengal didi ❤

  • @davidmwangi4312
    @davidmwangi4312 4 роки тому +4

    Great lecture. Concept Explained in simplest terms. Thank you, Jenny

  • @snehupadhyay5297
    @snehupadhyay5297 5 років тому +10

    Thanks a lot for this lacture. Your videos help me alot for my exams and you explain in a very good manner thanks once again.☺😊

  • @shwetananashankar1200
    @shwetananashankar1200 5 років тому +47

    There should be if clause instead of while, because we dont need loop. we are just comparing the values.

  • @vasan7234
    @vasan7234 5 років тому +3

    wow .. nice explanation.. i shared this video in my class group

  • @sasankgollapalli2689
    @sasankgollapalli2689 5 років тому +4

    I asked sorting in an mnc interview and and I passed it with flying colours✨✨ because of your vedios mam thanks alot Jenny mam for this excellent explanation 😍😍

  • @vartikasharma3355
    @vartikasharma3355 4 роки тому +2

    her teaching style is same as my college professor. just amazing

  • @birunath500
    @birunath500 2 роки тому

    Thank you ma'am. Your videos had helped me a lot before my exam. From your videos I could understand clearly. After that I recommended your videos to some of my friends too

  • @shihlihsu9918
    @shihlihsu9918 3 роки тому

    Always end up watching your video every SINGLE time. Thank you so much for all your tutorial.

  • @raghavclasses4587
    @raghavclasses4587 5 років тому +2

    mind blowing explaination...now am big fan of you

  • @NikitaSharma-bs4gg
    @NikitaSharma-bs4gg 4 роки тому +4

    That was amazing explanation; i was so stuck in heap sort part :,) thanks

  • @kritidiptoghosh4272
    @kritidiptoghosh4272 5 років тому +5

    Thanks. Keep up the good work.U just saved my semesters

  • @geekprobin1456
    @geekprobin1456 4 роки тому

    Maam, your way of teaching is awesome. Thanks a lot.

  • @DonGayanakaKariyawasam
    @DonGayanakaKariyawasam 4 місяці тому +1

    thank u miss , im computer sci student , this is very helpful

  • @sagarchaddha1538
    @sagarchaddha1538 4 роки тому +32

    In the deletion, our array size remained same as we are sending n in it!!
    Isn't it wrong,
    I think Maxheapify(A,i-1,1) would be there?

    • @decoder7101
      @decoder7101 3 роки тому +4

      Correct bro.
      And one more thing in place of while loops there will be simple if condition in heapify function.

    • @an_son_mathew_
      @an_son_mathew_ 3 роки тому

      Thank you so much brother......I had the same doubt ....

    • @akshatkumar2956
      @akshatkumar2956 3 роки тому

      Yes you r correct because after swapping 1st element with n th. Element. We have to heapify only at n-1, otherwise it will again heapify whole array

    • @BSEss
      @BSEss 3 роки тому +1

      @@akshatkumar2956 But bro i-- to already loop mein ho raha ha so shouldn't we write (A, i, 1) ?

    • @HenryPangsatabam
      @HenryPangsatabam 3 роки тому

      @@BSEss It would be wrong as we are making the swap first and calling the Heapify. For instance, if you include the n on the first iteration of Heapify, it would be swapped with its parent (n/2).

  • @check879
    @check879 4 роки тому +1

    It's a very good explanation. Keep up the good work, madam.

  • @rajeshr7182
    @rajeshr7182 4 роки тому +2

    Amazing explanation mam , no one can replace mam ! Almost k watched your videos it's very useful and understandable

  • @rutwickgangurde3247
    @rutwickgangurde3247 4 роки тому

    Preparing for interviews. I am told I have to be very good with DS. Been watching only your and Abdul Bari's videos for preparation. Good work, keep it up! Very easy way to explain.

  • @Parivarvad
    @Parivarvad 3 роки тому

    I learn Programing bcz of u,after failing before 8 yr ago,ummid jag gayi hai

  • @zainulaabdeen3893
    @zainulaabdeen3893 2 роки тому

    I love your way of explanation and your voice!

  • @arfinchowdhuryarif
    @arfinchowdhuryarif 4 роки тому +1

    39:22 is important....... Thanks for this easiest explanation........

  • @onlycinema1419
    @onlycinema1419 5 місяців тому

    one of the best Explanation i ever heard
    😍❤
    Thank U❤ Angel❤

  • @Forever._.curious..
    @Forever._.curious.. 2 роки тому +2

    Video is long but worth it 👍 thanks ma'am we study a lot with yr lecs 👍

  • @sanjayagarwal140
    @sanjayagarwal140 3 роки тому +1

    Tyvm for explaining such a complex operations in a simple and effective way

  • @frootyreuben6313
    @frootyreuben6313 2 роки тому +1

    Very good lecture this helped me alot in my exam to score better thankyou so much

  • @luckymishra8802
    @luckymishra8802 5 років тому +3

    Wow , mind blowing 😊😊😊 what a explaination

  • @yogendrayadav823
    @yogendrayadav823 11 місяців тому +1

    we are going to college for completing 75%attendance but there nothing to learn but actually we learn from you tube❤❤

  • @aeimenhafeez8144
    @aeimenhafeez8144 3 роки тому +1

    Today is my paper and I am so much confused about paper 🤣 firstly I think that I can,t perform good in paper . but now I am watching your videos to solve paper .so , finally I can say that I can perform best in paper🤩🥰.thanku mam💕❤️💖

  • @sohinikumar5096
    @sohinikumar5096 9 місяців тому

    Mam you are really a true teacher ❤ and your are very helpful 😊

  • @rajatpratapsingh4450
    @rajatpratapsingh4450 3 роки тому +1

    Thq so much mam , code bhi smjh me aa gya clearly......thq so much

  • @Nishant-ws5tj
    @Nishant-ws5tj 3 місяці тому

    Tomorrow is my exam ...really only u helped a lot ❤

  • @1minute741
    @1minute741 6 днів тому

    You are really good in teaching!

  • @hardimajmundar9653
    @hardimajmundar9653 5 років тому +2

    Thanks ma'am for all the videos. It helps a lot for solving all the problems in ADA nd DS.

  • @codesrhodes3757
    @codesrhodes3757 2 роки тому

    Ma'am your teaching is just amazing and brilliant 👏

  • @sagarnitcherla4306
    @sagarnitcherla4306 4 роки тому +1

    U re explanation is super

  • @MohdYahya-xv6sb
    @MohdYahya-xv6sb 4 роки тому

    Mam your explanation is always so simple and easy to understand thank you for putting these video's on UA-cam :)

  • @ashishidhol769
    @ashishidhol769 4 роки тому +1

    Good explanation with technical approach..

  • @tejassonawdekar
    @tejassonawdekar 5 років тому +45

    Me: Where can I learn Heap sort?
    Jenny: Here only.

    • @Atharhashmisir
      @Atharhashmisir 4 роки тому

      आप सभी देखने वालों से निवेदन है, एक बार मेरे चैनल पर आकर ज़रूर देखें
      ua-cam.com/users/AtharDhamtariplaylists

    • @constructivecritic8069
      @constructivecritic8069 4 роки тому +1

      @@Atharhashmisir lots of playlists...good content..wish u all the best..

  • @venkythesmart440
    @venkythesmart440 4 роки тому

    Mam a lot help full you'r lectures me and myfriends .upcoming generation teachers be like you teaching.so much better. I never forget you mam because.Internet using any work is done .this is possible. I proudly say.

  • @arkapravonandi3991
    @arkapravonandi3991 5 років тому +2

    The concept and the understanding the code by you is great

  • @rajaaqibumar1155
    @rajaaqibumar1155 2 роки тому

    Hey . You are very good teacher. your way of teaching is outstanding. lot of pakistani students follow your lectures and get good marks in exams. Outstanding

  • @malleboinasurekha986
    @malleboinasurekha986 2 роки тому

    Wonderfull explanation I can understand very well from your classes

  • @JackSparrow-h1z
    @JackSparrow-h1z Рік тому +19

    My college faculty copying your lectures mam😂

  • @mohit7834
    @mohit7834 5 років тому

    Aap. Bahut Sundar padhati hai 🙏🙏🙏🙏🙏

  • @sharmaankit8344
    @sharmaankit8344 5 місяців тому

    I watching many videos but not understand that video very help for me

  • @sobhityadav5753
    @sobhityadav5753 4 роки тому

    Very nice explanation....I am from babasaheb bhimrao ambedkar university...u are much better than my professors...

  • @te_b_52_siddeshpatankar14
    @te_b_52_siddeshpatankar14 3 роки тому

    Awesomeness appreciated👍🏻👍🏻👍🏻💯💯💯 Thanks a lot 🙏🏻🙏🏻🙏🏻

  • @tanaykulkarni2116
    @tanaykulkarni2116 4 роки тому

    till now all the videos helped me so much

  • @rtgamer9999
    @rtgamer9999 3 роки тому +1

    Mam your explanation so nice.
    It's very helpful for me .
    You are doing a great job.
    Thanq mam 😍