written 6.2 years ago by | modified 6.2 years ago by |
Topic: Applications of Queue
Difficulty: Medium
Year(Marks): May2017(5 mks)
written 6.2 years ago by | modified 6.2 years ago by |
Topic: Applications of Queue
Difficulty: Medium
Year(Marks): May2017(5 mks)
written 6.2 years ago by | modified 6.2 years ago by |
ADT for Queue is given as follows:-
typedef struct Queue { int rear,front; int data[max]; }queue;
Consider the following diagram of Queue
A. In operating systems:
In an OS multiple programs are executing at the same time.
Every process is associated with as state of the process which can be ready, running, blocked, wait, etc.
An OS maintains a queue of all such processes. The queue is used for scheduling these processes. Whenever a process completes execution, it is removed from queue and the next in queue are given turn. When a process changes its state, it is added to the queue and gets scheduled for execution.
B. Websites:
Queues are used for any situation where you want to efficiently maintain a First-in-first out order on some entities. These situations arise literally in every type of software development.
Imagine you have a web-site which serves files to thousands of users. You cannot service all requests, you can only handle say 100 at once.
A fair policy would be first-come-first serve: serve 100 at a time in order of arrival. A Queue would definitely be the most appropriate data structure.