[Question] Double-ended Queue JS implementation time complexity
coltonehrman opened this issue · 2 comments
coltonehrman commented
I see you are using Array.prototype.unshift
and Array.prototype.shift
as methods in the double-ended queue DS.
lago/lib/data-structures/Deque.js
Line 17 in 2ebdb22
lago/lib/data-structures/Deque.js
Line 25 in 2ebdb22
I believe these methods have O(n)
time complexity, shouldn't the queue's operations all be O(1)
time complexity?
coltonehrman commented
Ah... sorry, I should have dug deeper into the code before making these assumptions, I now realized you have a custom DoublyLinkedList class that has the same-named methods as the built-in array.
yangshun commented
That's awesome, thanks for digging deeper! :)