Notes on queues.

This commit is contained in:
John Washam 2016-06-18 19:47:49 -07:00
parent 7d604ee32a
commit b6b1203a31

View File

@ -217,10 +217,25 @@ Then test it out on a computer to make sure it's not buggy from syntax.
- https://class.coursera.org/algs4partI-010/lecture/18
- https://class.coursera.org/algs4partI-010/lecture/19
- https://www.lynda.com/Developer-Programming-Foundations-tutorials/Using-stacks-last-first-out/149042/177120-4.html
- Will not implement. Implementing with array is trivial.
Queues
- see: https://class.coursera.org/algs4partI-010/lecture
- https://class.coursera.org/algs4partI-010/lecture/20
- https://www.coursera.org/learn/data-structures/lecture/EShpq/queue
- Circular buffer/FIFO: https://en.wikipedia.org/wiki/Circular_buffer
- Implement using linked-list, with tail pointer:
- enqueue(value) - adds value at position at tail
- dequeue() - returns value and removes least recently added element (front)
- empty()
- Implement using fixed-sized array:
- enqueue(value) - adds item at end of available storage
- dequeue() - returns value and removes least recently added element
- empty()
- Cost:
- a bad implementation using linked list where you enqueue at head and dequeue at tail would be O(n)
because you'd need the next to last element, causing a full traversal each dequeue
enqueue: O(1) (linked list and array)
dequeue: O(1) (linked list and array)
empty: O(1) (linked list and array)
Hash tables
- https://www.youtube.com/watch?v=C4Kc8xzcA68
- https://class.coursera.org/algs4partI-010/lecture/52