Deque - Data Structure

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

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

  • @NamanRajpalAgra
    @NamanRajpalAgra 6 лет назад +68

    It s a bit confusing, when you say a deque has two properties, mentioning first one that its always sorted. It sounded like you are mentioning that it is one of the properties of data structure.
    You should clearly specify that it is sorted here in this case! We keep it sorted in THIS CASE.
    :) Good work otherwise. Your videos are very nice.

    • @gkcs
      @gkcs  6 лет назад +10

      That's true 😊

  • @minakshikudalkar557
    @minakshikudalkar557 4 года назад

    This explanation is so much better than the 'geeks for geeks' video

  • @doruwyl
    @doruwyl 5 лет назад +3

    Thank your in the name of all the viewers for this great explanation!

    • @gkcs
      @gkcs  5 лет назад

      Cheers 😁

  • @RahulVerma-fz2jf
    @RahulVerma-fz2jf 4 года назад +1

    I am a fan of you man. This video or your system design videos or any other videos you make, all have excellent content, and the best part is the way you explain, so easy to understand. I have solved this question, earlier as well, but couldn't solve it using deque again when I revisited it. I think, I won't forget it this time. :).
    Keep up the good work.

    • @gkcs
      @gkcs  4 года назад

      Thank you!

  • @pranavbansal9934
    @pranavbansal9934 4 года назад +2

    Very well explained,I am shocked such a easy concept exists then that of this sparse table!!

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

    Thank you for such an easy explanation of deque with a great use case.

  • @AlayDhagia
    @AlayDhagia 4 года назад +1

    why so many dislikes ? this was the perfect video I was looking for

  • @JigarGosar
    @JigarGosar 7 лет назад +11

    I appreciate your enthusiasm and dedication. Keep up the good work. It's very inspiring.
    PS: Keep smiling. I wonder what makes you so happy. Regardless its awesome😉

    • @gkcs
      @gkcs  7 лет назад +3

      Thanks Jigar :-D

  • @vishalanthony1529
    @vishalanthony1529 23 дня назад

    He is the kind of guy you would like as your team lead in your company

    • @gkcs
      @gkcs  23 дня назад

      Cheers :D

  • @vyshnavramesh9305
    @vyshnavramesh9305 4 года назад +3

    The worst case time complexity for this question using dequeue could be more detailed:
    O(n + n) // for enqueue and dequeue of each element
    +
    O((n/R - 1)* R) // for the repetition of accessing 'new element' to be compared with 'existing elements' in queue; where there would be n/R - 1 such 'new elements' in worst case and R 'existing elements' in queue for each of those new elements in worst case.
    Total: O (n + n + (n/R - 1)* R) = approx O(n)
    (The second part is where normally people think that wouldn't this cause the worst time complexity to be O(nR))
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Example 1: // worst case
    R = 10, n = 30
    array: 10 9 8 7 6 5 4 3 2 1 11 10 9 8 7 6 5 4 3 2 12 11 10 9 8 7 6 5 4 3
    For each of 11(first occurrence) and 12, there would be ten existing elements in queue to be compared with 11 and 12. Hence, 11 and 12 are accessed ten times each.
    Here, n/R - 1 = 30/10 - 1 = 2 elements, which are 11 and 12.
    These would be compared with R existing elements in queue: 2 * R = 2 * 10 = 20
    Example 2:
    A different case could be (n = 11, R = 10): 10 9 8 7 6 5 4 3 2 1 11
    Here, since only 1 element, 11, is getting repeatedly accessed with ten existing elements in queue, this would not be worser than the previous case, making the previous case the worst case.
    Please correct if wrong ^ _ ^

  • @gouravbansal994
    @gouravbansal994 3 года назад +1

    We have used DEQueue here and not Queue because we have to pop elements from both sides, although we are inserting elements from the back only.

  • @yanlingyang256
    @yanlingyang256 7 лет назад +3

    fairly impressed by your passion!!!!! really nice explanation. Thanks a lot :)

    • @gkcs
      @gkcs  7 лет назад

      Thanks Yanling :-)

  • @ishanshah3309
    @ishanshah3309 4 года назад

    This guy has excellent and deep understanding of data structures and algorithms and with good teaching skills he has nailed it to explain these concepts which is very helpful for beginners like me. Great work brother keep it doing !

  • @abhishes
    @abhishes 6 лет назад +3

    Is it pure O(n) because each time you add an item to the deque you scan all items on the left of the current element in the deque to see if any element is smaller than the current element. Thus depending upon the size of the queue you are doing multiple operations per element.

    • @gkcs
      @gkcs  6 лет назад +2

      Hey Abhishek! You can have a look at the amortized complexity video to get an idea. The total cost of all operations is still O(n).
      ruclips.net/video/MTl8djZFWE0/видео.html

    • @abhishes
      @abhishes 6 лет назад

      thanks. I will look at it.

    • @vijayanand6304
      @vijayanand6304 6 лет назад

      Gaurav Sen hi Gaurav, you mean you are trying to say, you remove from last too?

    • @gkcs
      @gkcs  6 лет назад

      Vijay Anand Yes we do. 'Poll last' does that.

  • @clyt9636
    @clyt9636 5 лет назад +2

    How do you convince yourself about the correctness of this technique. What is the invariant that is being maintained? Some of the points you could speak about. Good video

  • @vidhansharma1787
    @vidhansharma1787 5 лет назад +2

    Finally, DEQUE understood.......

  • @bismeetsingh352
    @bismeetsingh352 5 лет назад

    Remove first and Insert Last? Couldnt that be done with a Queue as well? Not sure why you need a Deque Here.

  • @rashibansal7357
    @rashibansal7357 4 года назад

    what if the array isn't sorted, if we will sort it, the output will change

  • @nitinkr28
    @nitinkr28 5 лет назад +2

    Nice Video. However Complexity is O(N*K) not O(N), as while removing obsolete elements we need to search index for those elements. O(N) can be achieved by checking the outgoing element in sliding window with head of Deque. In case of duplicates we need to store both instances.

    • @vyshnavramesh9305
      @vyshnavramesh9305 4 года назад +1

      Kindly have a look at stackoverflow.com/a/60108480/5649620

  • @principlesoflife172
    @principlesoflife172 7 лет назад +2

    I am not sure u need dequeue here. U are using only Queue - Remove first and Insert Last?

    • @gkcs
      @gkcs  6 лет назад +3

      We are removing from the front too :)

  • @dhvanilvadher1356
    @dhvanilvadher1356 5 лет назад

    Why is the compelexity of this algorithm is O(n) it should be O(n*k) please explain.

  • @hangoutwithabhi
    @hangoutwithabhi 3 года назад

    What if you use a PQ of size R ?

  • @bismeetsingh352
    @bismeetsingh352 5 лет назад

    is deque always sorted in nature? Is it a property of the data structure?

  • @sridharbajpai420
    @sridharbajpai420 5 лет назад

    but how will we find top element in bst ? which will be max

  • @shikharchaudhary6984
    @shikharchaudhary6984 4 года назад

    thanks, amazing explanation.

  • @MobiTechSpec
    @MobiTechSpec 5 лет назад

    Thanks for your teaching bro😘.

  • @vivek-ytr7p
    @vivek-ytr7p 5 лет назад

    Deque starts around 3:40

  • @surajagarwal4367
    @surajagarwal4367 7 лет назад +2

    nice video! if possible then plz explain with a little larger size of array. :)

  • @aakupsp
    @aakupsp 4 года назад

    Code implementation with detailed comments
    github.com/akuchotrani/CodingInterviewQuestions/blob/master/Leetcode/Leetcode%20Problem%20239%20Sliding%20Window%20Maximum.txt

  • @rohanjain4238
    @rohanjain4238 5 лет назад +1

    Great work man

  • @surajagarwal4367
    @surajagarwal4367 7 лет назад

    if i want to get the minimum at the very first index the i cant....is there any way to do this?

    • @gkcs
      @gkcs  7 лет назад +2

      Yes. One way would be to negate all the elements: a[i] = -1*a[i].
      Then the max at every range will actually be the min. When printing the answer, you could print -1*answer.

    • @surajagarwal4367
      @surajagarwal4367 7 лет назад

      got it thanks!
      if possible plz make videos on graph problems!

  • @deepanshukapoor
    @deepanshukapoor 7 лет назад +2

    please do video on cooking schedule from mar17 long challenge

    • @gkcs
      @gkcs  7 лет назад +1

      Thats an interesting problem. Did you try the editorial on codechef:
      discuss.codechef.com/questions/92702/schedule-editorial
      abx_2109 has a unique solution to this. Have a go at it, and if you still need help, I will be happy to make a video on this :-)

  • @sonkarshailendra
    @sonkarshailendra 4 года назад

    It's confusing. I couldn't understand.

  • @AnkitKumar-mf5vg
    @AnkitKumar-mf5vg 4 года назад

    It seems you are confused for BST approach
    And atleast take a larger array where you show the value of BST
    Size of two doesn't make any sense

  • @JoseAguirre-ri8tg
    @JoseAguirre-ri8tg 5 лет назад +1

    When you are explaining something you REALLY should slow down a bit. At some point I had to activate the subtitles.

  • @achalkumar8165
    @achalkumar8165 6 лет назад +1

    awesome work bro

    • @gkcs
      @gkcs  6 лет назад

      Thanks!.

  • @rejetimeghavardhan4186
    @rejetimeghavardhan4186 4 года назад +1

    very very thx bro @gaurav sen

  • @vishnuallala6191
    @vishnuallala6191 5 лет назад

    what if a[]=5,4,3,2,1,6,7 and k=6

    • @ananthsathvick5525
      @ananthsathvick5525 5 лет назад

      Basically you would have {5,4,3,2,1,6} as one sub array and {4,3,2,1,6,7} as another sub array
      So the output would be 6,7 (Maximum of first sub array and maximum of second sub array)

  • @patilsoham
    @patilsoham 5 лет назад

    Nicely explained buddy

    • @gkcs
      @gkcs  5 лет назад +1

      Thanks!

  • @gamingparlour1732
    @gamingparlour1732 5 лет назад

    I think this is priority queue

  • @Sourik24
    @Sourik24 7 лет назад +1

    If possible do a video on Trie data structure.

    • @gkcs
      @gkcs  7 лет назад

      Hi Sourik!
      Will put that data structure on the list, I have an interesting problem in mind for that :-D

  • @divyashreemh3950
    @divyashreemh3950 5 лет назад

    awesome Teaching Man

  • @phaneshravva7586
    @phaneshravva7586 7 лет назад

    Very clearly explained :)

    • @gkcs
      @gkcs  7 лет назад +1

      Thanks Phanesh!

  • @sparshsinha1881
    @sparshsinha1881 5 лет назад +2

    got it!.. thanks

  • @akashkarothiya
    @akashkarothiya 7 лет назад

    Nice Tutorial Gaurav :) If possible please make video on Multi-way tree, Happy Coding

    • @gkcs
      @gkcs  7 лет назад

      Nice suggestion Akash!
      I am in the process for making a tutorial on Tries. That would be a case of multi-way trees, so putting that in priority!

  • @sougatakundu8507
    @sougatakundu8507 6 месяцев назад

    Audio n video quality needs to be improved.

  • @shubhankarraj8519
    @shubhankarraj8519 4 года назад

    The explanation is totally confusing.

  • @avs700
    @avs700 4 года назад +4

    It's pronounced as "DECK"

  • @shreejitnair2174
    @shreejitnair2174 6 лет назад +1

    awesome explanation. please go a bit slow :)

    • @gkcs
      @gkcs  6 лет назад

      I hope my pace has improved now 😋

  • @Burhan_CSE
    @Burhan_CSE 7 лет назад

    really nice .....

    • @gkcs
      @gkcs  7 лет назад

      Thanks!

  • @jamunavijay7372
    @jamunavijay7372 6 лет назад +1

    super bro

  • @ayushthakur733
    @ayushthakur733 3 года назад

    all good coders are skiny

  • @akshaychopra651
    @akshaychopra651 3 года назад

    It's pronounced 'deck'.

  • @hrishabhgaur8999
    @hrishabhgaur8999 5 лет назад

    Why you motivate to make videos??