Heaps & Priority Queues - Heapify, Heap Sort, Heapq Library - DSA Course in Python Lecture 9

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

КОМЕНТАРІ • 50

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

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @mohammodroby8346
    @mohammodroby8346 16 годин тому

    Nice video brother. It help me a lot. Love you from Bangladesh.

  • @steventolerhan5110
    @steventolerhan5110 4 місяці тому +9

    Best video on heaps on youtube fr fr

  • @TaskForce141br
    @TaskForce141br Місяць тому +2

    On the pop is important that you substitute the top element by the rightmost element on the heap, that way you maintain the balance property of the heap, after that you heapify down.
    The way it was presented may cause confusion, beacause if you just remove the element on the top and do the rearranjement, the heap may become unbalanced

  • @Brusselsprouts2023
    @Brusselsprouts2023 Місяць тому

    wow! This channel is so underrated. Thankyou!!

  • @jingwen888wang
    @jingwen888wang Місяць тому +1

    The pop heap described h err e is incorrect, as it does not maintain the heap property which has the has the leaf nodes filled from left, so it messes up the array structure essentially, please pay attention to the details and correct it if it causes confusions.

  • @Dan-codes
    @Dan-codes 10 днів тому

    Excellent explanation, thank you

  • @garythegoat8341
    @garythegoat8341 2 місяці тому +1

    What would happen if that -10 was a leaf node when you were heapifying the min heap? The leaf nodes were ignored but presumably in that case that -10 would need to get to the top?

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

    thank you man to negate the values to use it as max heap was awesome trick ❤❤❤

    • @GregHogg
      @GregHogg  4 місяці тому

      Yeah I found that very cool when I first learned it too

  • @sonhoang8986
    @sonhoang8986 2 місяці тому

    Thank you for your explanation. I love how you explain the theory, but I expected more about the coding section. I hope something from scratch to understand the theory. Anw, thank you so much

  • @Jay-ek7uw
    @Jay-ek7uw 5 місяців тому

    These videos are great. Much love Greg

  • @updownftw
    @updownftw 29 днів тому +1

    Greg you missed the complete binary tree property of Heap at 5:20

  • @jonasjanaitis436
    @jonasjanaitis436 Місяць тому

    Great explanation.Thank you

  • @ahmedzz4754
    @ahmedzz4754 5 місяців тому +2

    Can't wait to see the dp or backtracking lesson (my national programming contest is soon and I suck a both)

  • @Karandeepsingh-kk2rv
    @Karandeepsingh-kk2rv 5 місяців тому +2

    Could you do a course on linked lists please?

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

    thank you so much for your clear explaination👍👍

  • @Abzal-pd9ri
    @Abzal-pd9ri 5 місяців тому +1

    Thank you a lot !! Please more videos like that

  • @navneetkumar9377
    @navneetkumar9377 4 місяці тому

    Quick question : How are you able to print the trees beautifully at 14:47 ? I can't find any inbuilt function.

  • @erons_xo
    @erons_xo 21 день тому

    Your tree at 11:55 doesn't satisfy the condition of a heap as the last level wasn't filled from left to right

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

    that was very helpful and clear thanks man you really great ♡♡

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

      Glad to hear it, thanks so much!

  • @godcomplex8251
    @godcomplex8251 2 місяці тому +1

    Actually I just looked this up in Sedgewick algo book, it says that heap construction is n.log(n)...

    • @DevendraYadav-pw9vp
      @DevendraYadav-pw9vp 2 місяці тому +1

      you are correct there is mistake just taking the position to correct spot is O(long) and for this to all n
      will extend the overall complexity to O(nlogn)

    • @godcomplex8251
      @godcomplex8251 2 місяці тому

      @GregHogg Love your videos but you should really correct or address mistakes like this, otherwise this can affect your credibility...

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

    23:45 You said the heap is set according to the smallest frequency. So why is (3,4) placed after (4,5) in the heap array?
    PS: Started watching this course recently, loving it so far!

    • @raafayhemani2018
      @raafayhemani2018 4 місяці тому

      The heap array is an array representation of a tree, if you wanted to get them in order you'd do a heapsort

  • @godcomplex8251
    @godcomplex8251 2 місяці тому

    Hey greg, wouldn't the Heapify function be O(n.log(n)), since for every node in the tree of N nodes, you need to perform "Sift down" which itself is O(log(n))?

    • @sitrucz
      @sitrucz Місяць тому

      No look for a proof. O(n)

  • @gaberhassan3972
    @gaberhassan3972 2 місяці тому

    very nice,👌👌👌👌 Thanks

  • @WilkinARuiz
    @WilkinARuiz Місяць тому

    Would heapq. Be ok to use in a coding interview? Wouldn't they want you to implement the code?

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

    thanks for sharing your view, i appreciate it

    • @GregHogg
      @GregHogg  5 місяців тому +1

      You're very welcome!

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

      not your view, but your way of teaching

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

    15:36 I thought heap pop have time complexity of 0(1)? Since you are just popping the minimum or the maximum (depends on what type of heap you have) at the top.

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

      Nope, peek has O(1) but to pop you need to fix the tree which is log n

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

      @GregHogg ok I see there's a difference.

  • @davenuada527
    @davenuada527 3 місяці тому +1

    What app do you use to draw on?

  • @asagiai4965
    @asagiai4965 5 місяців тому +2

    I'm surprised that idk that heaps and priority queues are same thing. Always thought they are different.

  • @atanumaiti16
    @atanumaiti16 4 місяці тому

    when u added 13 to the heap, it violates complete binary tree property.i think it should be added as right child of node 7. same goes with -2.

    • @sitrucz
      @sitrucz Місяць тому

      It’s not a binary tree. Order of children don’t matter.

  • @adventurer2395
    @adventurer2395 2 місяці тому +4

    0:15 bro hitting puberty lol. Great video, well explained

    • @Emivvvvv
      @Emivvvvv 2 місяці тому

      looool 😂

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

    684. Redundant Connection can u make video on this problem

  • @elyartaker1139
    @elyartaker1139 День тому

    Nice

  • @qulinxao
    @qulinxao 5 місяців тому +2

    sorry but in "real" pq only one(or zero) node have 1 child - others ether 0 or 2 - it simplifay :)