1 / 12

INTRODUCTION TO QUEUES

INTRODUCTION TO QUEUES. TOPICS TO BE DISCUSSED. QUEUES QUEUE APPLICATIONS FIRST IN FIRST OUT INSERT OPERATION DELETE OPERATION. QUEUES. Stores a set of elements in a particular order Q ueue principle: FIRST IN FIRST OUT = FIFO

Download Presentation

INTRODUCTION TO QUEUES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INTRODUCTION TO QUEUES

  2. TOPICS TO BE DISCUSSED QUEUES QUEUE APPLICATIONS FIRST IN FIRST OUT INSERT OPERATION DELETE OPERATION

  3. QUEUES Stores a set of elements in a particular order Queueprinciple: FIRST IN FIRST OUT = FIFO It means: the first element inserted is the first one to be removed The first one in line is the first one to be served

  4. QUEUE APPLICATIONS Real life examples Waiting in line Waiting on hold Applications related to Computer Science Threads Job scheduling (e.g. Round-Robin algorithm for CPU allocation)

  5. FIRST IN FIRST OUT 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.

  6. APPLICATIONS:JOB SCHEDULING

  7. INSERT OPERATION STEPS: • First check, is queue full? If queue full then terminate the operation. • Now check, is queue empty? • If queue is empty then set front pointer=1. • If queue is not full, then increase the rear pointer by 1. • Insert the element at the rear end.

  8. ALGORITHM…. STEP 1: [overflow condition ?] if R>=N then write “overflow” and return STEP 2: [is the queue empty ?] if F=0 then F:=1 [end of if statement] STEP 3: [increment rear pointer] R=R+1 STEP 4: [insert new element] Q[R]:=X STEP 5: [finished] return Q=name of queue N=maximum size of queue X=element to be inserted F= Front Pointer variable R= Rear Pointer variable

  9. DELETE OPERATION STEPS: • First check, is queue empty? If queue empty then terminate the operation. • If queue is not empty delete the front element from the queue. • If queue is empty after deletion of element then set the front and rear pointer equal to zero. • Now increase the front pointer by 1.

  10. ALGORITHM…. STEP 1: [underflow condition ?] if F=0 then write “underflow” and return STEP 2: [delete front element] X:=Q(F) STEP 3: [is queue now empty?] if F=R then[queue has only one element in start] F:=0,R:=0 and Return [end of if statement] STEP 4: [increment front pointer] F:=F+1 STEP 5: [finished] return Q=name of queue X=variable used to store deleted element F= Front Pointer variable R= Rear Pointer variable

  11. THANKS..

More Related