Sunday 24 June 2012

Queue


FIFO concept - First In First Out
- opposite to arrays, only one item can be read or removed at a given time - the oldest item inserted
- its size is predefined: only limited number of items can be added (pushed)
- underlying data structure can be array, vector, linked list

Usage:
- e.g. when performing tasks is slower than the rate tasks are received we want to save tasks in the same order they are received and we want first to execute the oldest tasks: we will put them in the queue

Operations:


Insertion (enqueue):

- Algorithm: item is added at the end (rear) of the queue
- Complexity: O(1)

Peek:


- Algorithm: return a value of the item from the front of the queue (the oldest item in the queue)
- Complexity: O(1)


Removal (dequeue):


- Algorithm: remove the item from the front of the queue (the oldest item in the queue)
- Complexity: O(1)

No comments:

Post a Comment