1 / 32

Circular Queue In Data Structure | Circular Queue Explained | Simplilearn

This presentation on Circular Queue in Data Structure will acquaint you with a clear understanding of circular queue implementation. In this presentation, you will understand array implementation and linked list implementation of circular queue using the C programming language. Finally, it will cover the applications of a circular queue to understand its importance. So, let's get started!<br><br>The topics covered in this Circular Queue In Data Structure slide are:<br>1. Introduction<br>2. Why was the Concept of Circular Queue Introduced?<br>3. Representation of Circular Queue Using Arrays and Linked Lists<br>

Simplilearn
Download Presentation

Circular Queue In Data Structure | Circular Queue Explained | Simplilearn

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. What's in It for You?

  2. Implementation of Circular Queue Using Array / Linked List Representation of Circular Queue Using Arrays and Linked List AGENDA Why Was the Concept of Circular Queue Introduced? Applications of the Circular Queue

  3. Click here to watch the video

  4. Why Was the Concept of Circular Queue Introduced?

  5. Why Circular Queue? In implementation of a linear queue, the drawback of memory wastage comes forward. Memory is a crucial resource that should be protected while designing Algorithms and solutions.

  6. Queue in Data Structure In Linear queue insertion is done at the rear node and deletion at the front node. FRONT (Deletion) REAR (Insertion) Initially, when the queue is empty, both Front and Rear Node point to the null memory space, i.e., -1.

  7. Queue in Data Structure As we keep adding elements into the array, Rear pointer reaches the end of the queue where front pointer remains at the same location. 7 -2 1 11 9 0 1 2 3 4 Rear Front

  8. Queue in Data Structure When we perform Dequeue() operations, the empty space gets created at the front node of the queue. 7 -2 1 11 9 0 1 2 3 4 Rear Front Empty space created after performing dequeue() operation!

  9. Introduction: Circular Queue A circular queue is extended version of linear queue with exception that last node of this queue is connected to its first, making a circular link. Circular Link 0 1 2 3 4 Rear Front

  10. Understanding: Circular Queue Let’s understand how memory wastage problem is getting resolved with the help of an example of circular queue. Newly Created Empty Space FRONT REAR 0 4 5 7 9 -2 11 1 3 1 2

  11. Representation of Circular Queue Using Array and Linked List

  12. Circular Incrementation A circular queue works with the process of circular Incrementation, i.e., When we reach the end of queue, we start from the beginning of a queue. FRONT REAR 5 0 12 7 -6 1 4 -2 1 7 2 3

  13. Circular Incrementation The rear pointer has reached the end of queue, but there is a empty space at the beginning of queue which can be utilized due to circular link. REAR 0 5 12 0 -6 1 4 Insertion of new element! 1 7 FRONT 2 3

  14. Implementation of Circular incrementation How can we perform circular incrementation logically? Let’s consider the example that we have discussed previously: MaxSize of queue = 6 Rear = 5 and Front = 2 Rear pointer should be brought at location 0 now. Rear = Rear + 1 = 5 + 1 = 6 Rear = (Rear + 1) % 6 Rear = (5 + 1)% 6 = 0 With help of Modulus operation we can achieve circular incrementation!

  15. Array Representation of Circular Queue The array representation of a circular queue is achieved using the method of circular incrementation. Circular Link 0 1 2 3 4 Rear Front

  16. Insertion Scenarios in Circular Queue Case 1: Determining if the queue is full. 7 -2 1 11 9 0 1 2 3 4 If((Rear + 1)%5 == Front) Rear Front (4+1)%5 = 0 = Front Return, Overflow Error.

  17. Insertion Scenarios in Circular Queue Case 2: When there is space at the beginning of a queue. New Insertion 5 1 11 9 0 1 2 3 4 Rear = (Rear + 1)%5 Rear Front Rear = (4+1)%5 = 0 Queue[Rear] = value

  18. Linked List Representation of Circular Queue The linked list representation of a circular queue can be achieved by changing the reference field of tail node. Tail Head Add 1 Add 1 Add 2 Address Circular Link is Created!

  19. Implementation of Circular Queue Using Array And Linked List

  20. Coding Implementation Let’s formulate the code for implementation of circular queue using array and Linked list!

  21. Let’s consider, MaxSize = 5, rear = 4, front =1 void Print() { int count = ((rear + MAX_SIZE - front) % MAX_SIZE)+1; int i; for (i = 0; i < count; i++) { printf("%d ", a[(front+i)%MAX_SIZE]); } printf("\n"); } 0 1 2 3 4 Count = ((4 + 5 – 1) % 5) + 1 = (8 % 5) +1 = 4 Rear Front We will read data elements using front pointer in range 0 to count.

  22. Applications of the Circular Queue

  23. Buffer in Operating Systems 01 Applications of the Circular Queue CPU Scheduling Algorithms 02 Computer Controlled Traffic Light Systems 03

  24. Buffer in Operating Systems A buffer is a region of a physical memory storage which temporarily stores the data while it is being moved from one place to another. Enqueue Audio Input Data Buffer Dequeue Audio Output

  25. Buffer in Video Streaming Netflix Servers Amazon Cloud Content Delivery Networks Content Delivery Network Audio Chunks Video Chunks Data Buffer: Receiver

  26. CPU Scheduling Algorithm The circular queue is used for developing the Round Robin Scheduling algorithm.

  27. CPU Scheduling Algorithm A Ready queue which is responsible for storing processes before resource allocation is implemented using a circular queue. Burst Time = 4 CPU Utilization time stamp = 2 µ sec P1 P2 P3 P4 P1 Ready Queue

  28. Computer Controlled Traffic System The traffic systems that are controlled by computers utilizes circular queue to manage activation of signal lights.

  29. Computer Controlled Traffic System Traffic lights will be lit in constant interval of time following FIFO principle. Control Queue Y R G

More Related