Skip to content

Latest commit

 

History

History
57 lines (44 loc) · 2.46 KB

Queue_notes.md

File metadata and controls

57 lines (44 loc) · 2.46 KB

Definition and Overview:

A Queue is a linear data structure that follows the FIFO (First In, First Out) principle. It represents a collection of elements with two primary operations: enqueue (insertion) and dequeue (removal).

Basic Operations:

  1. Enqueue: Adds an element to the rear end of the queue.
  2. Dequeue: Removes an element from the front end of the queue.

Characteristics:

  1. Front and Rear Pointers: These pointers indicate the starting and ending positions of the queue.
  2. Empty Queue: When Front and Rear are both -1 or Front > Rear.
  3. Full Queue: Occurs when Rear reaches the maximum size (SIZE - 1 in the provided example).

Implementation:

Array Implementation: The queue can be implemented using arrays or linked lists.

Array Implementation Properties:

  1. inp_arr[] holds the elements in the queue.
  2. Front and Rear pointers denote the positions for insertion and deletion.

Operations Complexity:

  1. Enqueue: O(1) - Constant time complexity.
  2. Dequeue: O(1) - Constant time complexity.
  3. Accessing Front Element: O(1) - Directly accessible.

Application of Circular Queue-based Message Queues:

Inter-Process Communication (IPC):

  1. Facilitates data exchange between processes or threads asynchronously.
  2. Enhances system efficiency and allows for independent communication.

Operating Systems:

  1. Utilized for task scheduling based on priority or predefined schedules.
  2. Enables efficient resource sharing among processes.

Networking:

  1. Handles incoming/outgoing data packets in network devices.
  2. Manages buffer and flow control in networking systems.

Embedded Systems:

  1. Supports device communication and coordination in hardware.
  2. Helps manage events and commands in embedded systems.

Real-time Systems:

  1. Prioritizes tasks for timely execution in real-time environments.
  2. Manages asynchronous event-driven architectures efficiently.

Fault Tolerance and Load Balancing:

  1. Enables redundancy and failover mechanisms for system reliability.
  2. Assists in load balancing by distributing messages across components.

Queue Variants:

  1. Priority Queue: A queue where elements have a certain priority and are dequeued based on that priority.
  2. Circular Queue: A variant where the rear end is connected to the front end, utilizing the entire array effectively.

Error Handling:

  1. Overflow: Occurs when trying to enqueue an element into a full queue.
  2. Underflow: Occurs when trying to dequeue from an empty queue.