Google+

Tuesday, 6 January 2015

Algorithm: Queue :Post 8

Queue:
The programming mantra: Queue

In computer science, a queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position, known as enqueue, and removal of entities from the front terminal position, known as dequeue.
This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed.
This is equivalent to the requirement that once a new element is added, all elements that were added before have to be removed before the new element can be removed. Often a peek or front operation is also entered, returning the value of the front element without dequeuing it. A queue is an example of a linear data structure, or more abstractly a sequential collection.



Queue<item-type> Operations:

enqueue(new-item:item-type)
Adds an item onto the end of the queue

front():item-type
Returns the item at the front of the queue.

dequeue():
Removes the item from the front of the queue.

is-empty():
BooleanTrue if no more items can be dequeued and there is no front item.

is-full():
BooleanTrue if no more items can be enqueued.

get-size():
IntegerReturns the number of elements in the queue.

All operations except get-size() can be performed in time. get-size() runs in at worst



Basic Features:
1. Like Stack ,queue is also an ordered list of elements.
2. It also contains similar data types.
3. Once a new element is inserted into the queue, all the elements inserted before the new elements          must be removed, to remove new element.
4. Queue is a FIFO (first in first out structure)
5. peek( ) function is often used to return the value of the element with out dequeuing it.

Application of Queue:
Queue can be used to implement situation that uses technique similar to real life queues.


Applications of Queue 

Queue is used when things don’t have to be processed immediately, but have to be processed in First In First Out order like Breadth First Search. This property of Queue makes it also useful in following kind of scenarios.

1) When a resource is shared among multiple consumers. Examples include CPU scheduling, Disk Scheduling.
2) When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes. Examples include IO Buffers, pipes, file IO, etc.

the implementation of stack and queue will be explained later

Next will be linklist.

No comments:

Post a Comment