Lecture Notes for SE 598, Data Structures and Algorithms
28 June 2000, Implementing Dequeues
- operations and behavior
- create - create a dequeue
- delete - delete a dequeue
- read - place a value in a dequeue
- write - retrieve a value from a dequeue
- grow - add a new element to the end of the dequeue
- shrink - delete an element from the end of the dequeue
- size - return the number of elements in a dequeue
- design
- what data structures are best for implementing dequeues?
- how can the operations best be implemented?
- these questions are related
- the interesting point is that dequeues can grow and shrink from both
ends
- use an array
- an array with two pointers, one to the front and one to the back
- creating and deleting is fast and simple
- reading and writing is fast and of slight complexity
- grow is slow and moderately complex, shrink is fast and slightly
complex
- if array space exists, move an end pointer for new space
- for a linear array, shift contents to open up space
- for a circular array, not a problem
- for a full array, grow requires copying in either case
- size is fast and easy, possibly with an auxiliary variable
- use a linked list
- have a head with two pointers, one to the front and the other to the
back
- creating is fast and simple, deleting is slow and simple
- reading and writing are slow and slightly complex
- grow and shrink are fast and simple
- size is fast and simple with an auxiliary variable
- combine linked lists and arrays
- use a linked list with an linear array index
- creating is fast and moderately complex, deleting is slow and simple
- reading and writing are fast and moderately complex
- grow is slightly slow and moderately complex, shrink is fast and
simple
- size is fast and simple with an auxiliary variable
- grouping linked-list elements into arrays improves grow performance
- use two vectors
- each vector represents an end of the dequeue
- creating is fast and simple
- reading and writing are fast and slightly complex
- grow and shrink are fast and slightly complex
- size is fast and simple
This page last modified on 26 June 2000.