SACHIN KHARADE Introduction Queue is an ADT data

  • Slides: 13
Download presentation
SACHIN KHARADE

SACHIN KHARADE

Introduction � Queue is an ADT data structure similar to stack, except that the

Introduction � Queue is an ADT data structure similar to stack, except that the first item to be inserted is the first one to be removed. � This mechanism is called First-In-First-Out (FIFO). � Placing an item in a queue is called “insertion or enqueue”, which is done at the end of the queue called “rear”. � Removing an item from a queue is called “deletion or dequeue”, which is done at the other end of the queue called “front”. � Some of the applications are : printer queue, keystroke queue, etc. SACHIN KHARADE

A push. A front back A B push. B front back A front B

A push. A front back A B push. B front back A front B C push. C B C front back A Queue is a FIFO (First in First Out) Data Structure. Elements are inserted in the Rear of the queue and are removed at the Front. back pop. A pop. B SACHIN KHARADE

Representation Of Queue � Using An Array � Using A Linked List SACHIN KHARADE

Representation Of Queue � Using An Array � Using A Linked List SACHIN KHARADE

3 States Of Queue � Queue is Empty : � Front = Rear �

3 States Of Queue � Queue is Empty : � Front = Rear � Queue is Full : � Rear = N � Queue contains element >=1: � Front < Rear � No. Of Element = Rear – Front + 1 SACHIN KHARADE

Applications Of Queue � Real Life Applications � Waiting in line � Waiting on

Applications Of Queue � Real Life Applications � Waiting in line � Waiting on hold for tech support � Applications Related to computer life � Round Robin Scheduling � Job Scheduling � Key Board Buffer SACHIN KHARADE

Types Of Queue � Circular Queue � Double Ended Queue (Deque) � Priority Queue

Types Of Queue � Circular Queue � Double Ended Queue (Deque) � Priority Queue SACHIN KHARADE

Circular Queue � When a new item is inserted at the rear, the pointer

Circular Queue � When a new item is inserted at the rear, the pointer to rear moves upwards. � Similarly, when an item is deleted from the queue the front arrow moves downwards. � After a few insert and delete operations the rear might reach the end of the queue and no more items can be inserted although the items from the front of the queue have been deleted and there is space in the queue. � To solve this problem, queues implement wrapping around. Such queues are called Circular Queues. � Both the front and the rear pointers wrap around to the beginning of the array SACHIN KHARADE

Double – Ended Queue (Deque) � Items can be inserted and deleted from either

Double – Ended Queue (Deque) � Items can be inserted and deleted from either ends. � I nput Restricted Deque: Elements can be inserted at only at one end but can be removed from both ends. � Output Restricted Deque: Elements can be inserted at both ends and can be removed only from one side SACHIN KHARADE

Operations On Deque � Insert element at back � Insert element at front �

Operations On Deque � Insert element at back � Insert element at front � Remove element at back SACHIN KHARADE

Applications Of Deque A-Steal job scheduling algorithm � The A-Steal algorithm implements task scheduling

Applications Of Deque A-Steal job scheduling algorithm � The A-Steal algorithm implements task scheduling for several processors(multiprocessor scheduling). � The processor gets the first element from the deque. � When one of the processor completes execution of its own threads it can steal a thread from another processor. � It gets th e last element from the deque of another processor and executes it. Undo-Redo : operations. SACHIN in Software KHARADE applications.

Priority Queue � A Special form of queue from which items are removed according

Priority Queue � A Special form of queue from which items are removed according to their designated priority and not the order in which they entered. � Items are removed from the front. � Items are ordered by key value so that the item with the lowest key (or highest) is always at the front. � Items are inserted in proper position to maintain the order. SACHIN KHARADE

Applications Of Priority Queue � Standby flyers � Auctions � Stock market � Sorting

Applications Of Priority Queue � Standby flyers � Auctions � Stock market � Sorting � Huffman Coding SACHIN KHARADE