yangshun/lago

[Question] Double-ended Queue JS implementation time complexity

coltonehrman opened this issue · 2 comments

I see you are using Array.prototype.unshift and Array.prototype.shift as methods in the double-ended queue DS.

this.unshift(element);

return this.shift();

I believe these methods have O(n) time complexity, shouldn't the queue's operations all be O(1) time complexity?

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.

That's awesome, thanks for digging deeper! :)