The Best Data Structure You’ve Never Heard of | Python Deques

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024

Комментарии • 13

  • @Darkev77
    @Darkev77 9 месяцев назад +6

    This is legendary content, so glad I found this gem that unearths low level concepts from high level ones, especially in Python

    • @DanielBoctor
      @DanielBoctor  9 месяцев назад +2

      You really just binged half my channel LOL you are the real legend here. I appreciate the support, it means a lot ❤️. I'm glad they're helpful

  • @sanderbos4243
    @sanderbos4243 Год назад +6

    I love deques/circular buffers, they are immensely useful (apart from the name; my friend refuses to call it deck and pronounces it dequeue, which is understandable, but that name also means popping from a queue)
    In my experience however the order of elements in a list/array often doesn't matter, and so you can just use the "swap-remove" `lst[i] = lst.pop()` to remove any element you want in O(1), which is especially useful in C, where you'd have to write a small deque library otherwise :)

    • @DanielBoctor
      @DanielBoctor  Год назад +3

      I also used to call them dequeues when I first learnt about them LOL.
      That's an incredible tip btw, I never thought of that myself! Quite elegant. Thanks for sharing

    • @sanderbos4243
      @sanderbos4243 Год назад +2

      @@DanielBoctor In C it's surprisingly also a single line, btw! `arr[i] = arr[--len];`

    • @DanielBoctor
      @DanielBoctor  Год назад +2

      What a beautiful line of code

  • @mangopolice
    @mangopolice 7 месяцев назад +1

    I love how you teach so much in just 3 minutes

  • @__Merchant
    @__Merchant 3 месяца назад +1

    While deques are faster, they declare slower. (for example: my_deque = deque(100_000_000) takes at least 2 seconds for me) I was confused why it was slower for me until I started timing it in all sorts of ways using your examples. They are faster in everything else but are slower at declaring. this however does not matter much in smaller deques.

  • @romanpisani8157
    @romanpisani8157 20 дней назад

    n / 2 isn't a time complexity? You could have been more clear with that last part

  • @Iearnwithme
    @Iearnwithme 8 месяцев назад +1

    Great video again, very insightful! I have a DataFrame, for which I can also make into a list / a duque for each index I am interacting through where I am sorting the data. Would sorting be effected by the format? For context I am sorting all past constituents of the Russell 3000 back to 1990 sorting by market cap each day.
    Regardless, keep it up!

    • @DanielBoctor
      @DanielBoctor  8 месяцев назад +1

      Thank you! I can't say for certain without more information, however DataFrames would almost certainly be the optimal way to sort data. They are specifically designed to handle and manipulate large datasets efficiently. My time complexity video actually dives into this topic a little bit, showing some of the advantages of vectorization and parallel computation, which are handled implicitly for you within DataFrames.

    • @Iearnwithme
      @Iearnwithme 8 месяцев назад

      @@DanielBoctor Brilliant! I need to learn that - thank you for the guidance

  • @SaqibMubarak
    @SaqibMubarak Год назад +1

    bro.......
    it's literally a first yr chapter