-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
03 prework stacks queues dequeues #4
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this and sorry about the delay! I'll try to respond sooner next time.
* [Dequeues](https://bradfieldcs.com/algos/deques/introduction/) | ||
|
||
### Questions | ||
1. What is the difference between an abstract data type and an implementation of a data structure? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great descriptions here!
| | Dynamic Array | Doubly Linked List | | ||
| --- | --- | --- | | ||
| Push | o(1) amortized | o(1) | | ||
| Pop | o(1) | o(1) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the discussion from class, would you agree now that dequeueing is actually O(n)?
self._items.push(item) | ||
|
||
def dequeue(self): | ||
return self._items.pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected behavior of a Queue is: you get the items back in the order you enqueued them. Will this implementation give you such behavior?
Potential performance differences | ||
* Need to update pointers for the doubly linked list. No need to update pointers for the dynamic array. Not sure how this affects performance | ||
* If we want to view an item that is not at the start or the end of the queue, it is faster to do so in a dynamic array since lookup is o(1) time, whereas it is o(n) time in a doubly linked list. | ||
* Dynamic array has items in contiguous memory. There might be a limit to how large this queue can become and the limit is the largest block of contiguous memory that the disk has. This limit could be lower on a very fragmented disk (memories of Windows 98 here) Doubly linked lists (and single linked lists) can store their contents all over a disk regardless of contiguous memory, and thus the queue size limit is probably higher. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point about fragmentation!
|
||
Potential performance differences | ||
* Need to update pointers for the doubly linked list. No need to update pointers for the dynamic array. Not sure how this affects performance | ||
* If we want to view an item that is not at the start or the end of the queue, it is faster to do so in a dynamic array since lookup is o(1) time, whereas it is o(n) time in a doubly linked list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. That being said, since your interface wouldn't even allow for viewing such items, this likely wouldn't be something you need to worry about.
| Pop | o(1) | o(1) | | ||
|
||
Potential performance differences | ||
* Need to update pointers for the doubly linked list. No need to update pointers for the dynamic array. Not sure how this affects performance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A pointer update can be done in constant time (it's just reassigning a variable).
No description provided.