0% found this document useful (0 votes)
101 views4 pages

Class 12 Notes Computer Science Chap 4

Uploaded by

Prateek singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views4 pages

Class 12 Notes Computer Science Chap 4

Uploaded by

Prateek singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Artham Resource

CLASS – 12
COMPUTER SCIENCE
NOTES
CHAPTER-4 QUEUE

Introduction
Queue is a fundamental data structure in computer science that operates on the First-In-First-Out (FIFO)
principle. This chapter explores the concept of queues, their operations, types, and applications. Queues are used
in various scenarios such as task scheduling, handling requests in systems, and more.

1. Basics of Queue
A. Definition

• Queue: A linear data structure that follows the FIFO (First-In-First-Out) principle, meaning that the first element
added to the queue will be the first one to be removed.

B. Operations on Queue

1. Enqueue
o Definition: The process of adding an element to the end of the queue.
o Operation: Inserts an element at the rear (end) of the queue.
2. Dequeue
o Definition: The process of removing an element from the front of the queue.
o Operation: Removes an element from the front of the queue and returns it.
3. Front
o Definition: Accesses the front element of the queue without removing it.
o Operation: Retrieves the element at the front.
4. Rear
o Definition: Accesses the rear (last) element of the queue.
o Operation: Retrieves the element at the rear.
5. IsEmpty
o Definition: Checks whether the queue is empty.
o Operation: Returns true if the queue has no elements; otherwise, false.
6. IsFull
o Definition: Checks whether the queue is full.
o Operation: Returns true if the queue has reached its maximum capacity; otherwise, false.

JOIN OUR WHATSAPP GROUP


2. Types of Queues
A. Simple Queue

• Description: The basic form of a queue where elements are added at the rear and removed from the front.
• Operations: Supports enqueue, dequeue, front, rear, isEmpty, and isFull operations.

B. Circular Queue

• Description: A queue where the last position is connected back to the first position to make a circular structure.
• Advantages:
o Efficient use of space compared to a simple queue.
o Easier to manage when the queue becomes full.
• Operations: Similar to a simple queue but uses modulo arithmetic to wrap around the end of the queue.

C. Priority Queue

• Description: A queue where each element has a priority associated with it. Elements are dequeued based on their
priority rather than their order of insertion.
• Types:
o Max Priority Queue: Elements with higher priority are dequeued before elements with lower priority.
o Min Priority Queue: Elements with lower priority are dequeued before elements with higher priority.

D. Double-Ended Queue (Deque)

• Description: A queue that allows insertion and deletion of elements from both ends (front and rear).
• Operations:
o InsertFront: Inserts an element at the front.
o InsertRear: Inserts an element at the rear.
o DeleteFront: Removes an element from the front.
o DeleteRear: Removes an element from the rear.
• Applications: Useful in scenarios where both ends need to be manipulated.

3. Implementation of Queue
A. Queue Implementation Using Arrays

1. Structure:
o Array: Used to store queue elements.
o Front: Index of the front element.
o Rear: Index of the rear element.
2. Operations:
o Enqueue: Insert at rear and update rear.
o Dequeue: Remove from front and update front.
o Front: Return the element at the front index.
o Rear: Return the element at the rear index.

JOIN OUR WHATSAPP GROUP


3. Circular Queue Implementation:
o Use modulo arithmetic to handle wrapping around the end of the array.
o Enqueue: (rear + 1) % size for the next rear position.
o Dequeue: (front + 1) % size for the next front position.

B. Queue Implementation Using Linked Lists

1. Structure:
o Node: Contains data and a reference to the next node.
o Front: Points to the head of the list (first element).
o Rear: Points to the tail of the list (last element).
2. Operations:
o Enqueue: Create a new node and link it to the rear, update rear.
o Dequeue: Remove the node pointed to by front, update front.
o Front: Return the data of the node pointed to by front.
o Rear: Return the data of the node pointed to by rear.

4. Applications of Queues
1. Task Scheduling
o Description: Operating systems use queues to manage tasks and processes, ensuring that tasks are
executed in the order they are requested.
2. Breadth-First Search (BFS)
o Description: A graph traversal algorithm that uses a queue to explore nodes level by level.
3. Print Queue
o Description: Manages print jobs in a printer, ensuring that documents are printed in the order they are
received.
4. Call Centers
o Description: Manages incoming customer service calls by placing them in a queue and handling them in
the order they arrive.
5. Data Buffering
o Description: Buffers in networks or file systems use queues to manage data packets or chunks efficiently.

5. Queue Variants and Related Data Structures


A. Circular Queue

• Definition: A type of queue where the last position is connected back to the first position, forming a circle.
• Advantages: Prevents wastage of space, efficient for implementing fixed-size queues.

B. Priority Queue

• Definition: A queue where elements are served based on priority rather than order of insertion.
• Implementation: Often implemented using heaps (binary heaps) to maintain order based on priority.

C. Deque (Double-Ended Queue)

• Definition: A data structure that allows insertion and deletion at both ends.
• Implementation: Can be implemented using doubly linked lists or circular arrays.

JOIN OUR WHATSAPP GROUP


6. Algorithms and Complexity
A. Complexity Analysis

• Enqueue Operation: O(1) in both array and linked list implementations.


• Dequeue Operation: O(1) in both array and linked list implementations.
• Circular Queue Wrap-Around: Ensures O(1) complexity for enqueue and dequeue operations.

B. Queue Implementation Efficiency

• Array-Based Queue: Requires careful handling of wrap-around in circular queues.


• Linked List-Based Queue: Flexible size but may involve additional overhead for node management.

7. Summary and Practice Questions


A. Summary

• A queue is a linear data structure that follows the FIFO principle.


• Queues can be implemented using arrays or linked lists and come in various types like simple queues, circular
queues, priority queues, and deques.
• Applications of queues span across task scheduling, data buffering, and more.

B. Practice Questions

1. Explain the difference between a simple queue and a circular queue. How does the circular queue
optimize space usage?
2. Describe the operations of a priority queue and how they differ from a regular queue.
3. Implement a queue using an array and demonstrate the enqueue and dequeue operations.
4. Compare and contrast the performance and use cases of queue implementations using arrays vs.
linked lists.
5. Provide examples of real-world applications of queues and explain how queues are utilized in those
scenarios.

JOIN OUR WHATSAPP GROUP

You might also like