9CM Name :B Vijaya kumari Designation : Lecturer Branch :Computer Engineering Institute :Smt.B.Seetha. Polytechnic, Bhimavaram, Year/semester :III Sem Subject :Datastructrues Through C Sub code : 9CM-305 Topic :stacks& queues Duration :50 mins Subtopic :Data structure Sub topic :Circular queue using array implementation Teaching aids: :PPT, animations, Photographs Revised by : Bapuji naik Department Of Technical Education Andhra Pradesh
9CM Recap In the last class we have discussed about Queue using linked list.
9CM Objectives On completion of this topic, you would be able to know Circular queue Operation on circular queue
9CM Recap In the previous lesson we have learnt, implementation of circular queue using linked list
9CM Reading queues implementation with array has the drawback When an element is inserted, rear pointer is incremented Similarly when we delete element, front pointer is incremented Drawbacks of Queue
9CM Once we delete the element, there is no way to re use that location of the queue. In the above diagram, location with index 0 can not be re – used, as the operation manipulations any rear pointer not be front picture. Drawbacks of Queue Contd.,
9CM The problem can be overcome, if there is a facility to re – use the location indices. i.e., Once the maximum value of index in reached for either of front order, nest increment should point to the beginning of the queue. Drawbacks of Queue Contd.,
9CM For example, if the queue size in 5 the index value range from 0 to 4. Once the front of rear value reaches 4, nest of increment of either of them should problem 0. This is possible is the queue is arranged circularly Drawbacks of Queue Contd.,
9CM From the above discussion, it is clean that the location can be re used if we represent the queue circularly It make efficient uses if location of queue In a circular queue the last element and the first element of the queue are adjacent to each other Circular queue
9CM Representation of circular queue diagrammatically circular queue are representation as follows. The above queue has 6 location, index value range is 0 to 5 Once index value is 5, the next index is 0.
9CM Operations on circular queues The operations add the element at rear of the queue Delete operation deletes an element at front of the queue
9CM Initially front and rear have 0 value Diagrammatically, frontrear All elements are initially 0 Also, front = rear= 0 Operations on circular queues Contd., 5
9CM By adding an element ‘u‘ Front=0,rear=4 Operations on circular queues Contd., front rear u
9CM By adding some more elements the diagram look like, In the above diagram, A,E, S are added to the circular queue. front=0,rear=4 Operations on circular queues Contd., u a e s front0 rear
9CM Both the above scenario if we add two more elements the from are rear value are front=0, and rear=o front 5p q u a e s s rear Operations on circular queues Contd.,
9CM As, it can be draw, where the queue is empty the value of front are rear front=rear=0 Similarly, when the queue is full front=rear=0 on queue empty and queue full condition, front=rear=0 Contd., Operations on circular queues
9CM So for add a parathions were discussed On deleting element from the queue front is incremented front 0 0 e a u 5 rear front e a rear 5 u Contd., Operations on circular queues
9CM Before deletion front=0,rear=3 After deletion front=1,rear=3 The element value at front =1,u,is a no more usuful The location can be re- used later Continually with deletion, if the delete some more elements, the queue becomes empty. Again, the value of front and rear are front=0, rear=0 Contd., Operations on circular queues
9CM Summary In this lesson we have learnt The need for circular queue Representation of circular queue Operation of circular queue -add -delete Examples of operator
9CM Quiz 1.Regular queue are more efficient, compared to circular queue in array implementation a)True b)false
9CM The value of front are rear zero, in case of queue full as well as queue empty a) True b) false Quiz Contd.,
9CM In which situation head and tail pointers are points to same location a)Queue is full b)Queue is empty c)Both a&b d)None Quiz Contd.,
9CM In which end additions are made a)Head b)Tail c)Middle d)None Quiz Contd.,
9CM If queue is full then a)Head and tail pointers are points to same location b)Head and tail pointers are points to different locations c)a&b d)none Quiz Contd.,
9CM If queue is empty then a)Head and tail pointers are points to different locations b)Head and tail pointers are points to same location c)Both head and tail pointers are points to middle point d)a&c Quiz Contd.,
9CM In dequeue operation the tail pointer is a) incremented b) Decremented c) a&b d) None Quiz Contd.,
9CM In enqueue operation the head pointer is a) Incremented a)Decremented b)Same point c)b&c Quiz Contd.,
9CM Frequently asked questions 1.What is a circular queue? 2.Explain the operations of circular queue? 3.Explain full and empty conditions of a circular queue?
9CM