Presentation is loading. Please wait.

Presentation is loading. Please wait.

9CM305.311 Name :B Vijaya kumari Designation : Lecturer Branch :Computer Engineering Institute :Smt.B.Seetha. Polytechnic, Bhimavaram, Year/semester :III.

Similar presentations


Presentation on theme: "9CM305.311 Name :B Vijaya kumari Designation : Lecturer Branch :Computer Engineering Institute :Smt.B.Seetha. Polytechnic, Bhimavaram, Year/semester :III."— Presentation transcript:

1 9CM305.311 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

2 9CM305.312 Recap In the last class we have discussed about Queue using linked list.

3 9CM305.313 Objectives On completion of this topic, you would be able to know Circular queue Operation on circular queue

4 9CM305.314 Recap In the previous lesson we have learnt, implementation of circular queue using linked list

5 9CM305.315 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

6 9CM305.316 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.,

7 9CM305.317 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.,

8 9CM305.318 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.,

9 9CM305.319 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

10 9CM305.3110 2 1 3 4 50 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.

11 9CM305.3111 Operations on circular queues The operations add the element at rear of the queue Delete operation deletes an element at front of the queue

12 9CM305.3112 Initially front and rear have 0 value Diagrammatically, 2 1 3 4 frontrear All elements are initially 0 Also, front = rear= 0 Operations on circular queues Contd., 5

13 9CM305.3113 By adding an element ‘u‘ Front=0,rear=4 Operations on circular queues Contd., front rear 0 1 2 3 4 5 6 7 u

14 9CM305.3114 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 1 2 3 4 5 6 7

15 9CM305.3115 Both the above scenario if we add two more elements the from are rear value are front=0, and rear=o 0 2 3 4 1 front 5p q u a e s s rear Operations on circular queues Contd.,

16 9CM305.3116 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

17 9CM305.3117 So for add a parathions were discussed On deleting element from the queue front is incremented 0 2 3 4 1 front 0 0 e a u 5 rear front 0 2 3 4 1 0 0 e a rear 5 u Contd., Operations on circular queues

18 9CM305.3118 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

19 9CM305.3119 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

20 9CM305.3120 Quiz 1.Regular queue are more efficient, compared to circular queue in array implementation a)True b)false

21 9CM305.3121 2. The value of front are rear zero, in case of queue full as well as queue empty a) True b) false Quiz Contd.,

22 9CM305.3122 3. 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.,

23 9CM305.3123 4. In which end additions are made a)Head b)Tail c)Middle d)None Quiz Contd.,

24 9CM305.3124 5. 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.,

25 9CM305.3125 6. 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.,

26 9CM305.3126 7. In dequeue operation the tail pointer is a) incremented b) Decremented c) a&b d) None Quiz Contd.,

27 9CM305.3127 8. In enqueue operation the head pointer is a) Incremented a)Decremented b)Same point c)b&c Quiz Contd.,

28 9CM305.3128 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?

29 9CM305.3129


Download ppt "9CM305.311 Name :B Vijaya kumari Designation : Lecturer Branch :Computer Engineering Institute :Smt.B.Seetha. Polytechnic, Bhimavaram, Year/semester :III."

Similar presentations


Ads by Google