0% found this document useful (0 votes)
18 views

Simple Queue or Linear Queue

queue

Uploaded by

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

Simple Queue or Linear Queue

queue

Uploaded by

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

 Simple Queue or Linear Queue: This is the basic type of queue where the insertion is done at

one end (rear) and the deletion is done at the other end (front). It has a drawback of wasting
space when the front elements are deleted and the rear reaches the end of the array.

 Circular Queue: This type of queue overcomes the drawback of simple queue by connecting the
rear and front ends of the array. It forms a circular shape and allows insertion and deletion at
any position. It utilizes the memory efficiently and avoids overflow condition.

 Priority Queue: This type of queue assigns a priority to each element and arranges them
accordingly. The element with the highest priority is removed first, regardless of its order of
insertion. It is useful for applications like CPU scheduling, disk scheduling, etc.

 Double Ended Queue (or Deque): This type of queue allows insertion and deletion at both ends
(front and rear). It is more flexible than simple queue and can be used to implement stacks and
queues

 A queue is an abstract data type that represents a collection of


elements that follow the FIFO (First-In-First-Out) principle. It means
that the element that is inserted first is removed first. A queue has two
basic operations: enqueue and dequeue. Enqueue adds an element to
the back of the queue, and dequeue removes an element from the
front of the queue. A queue can also have other operations, such as
peek, which returns the value of the next element to be dequeued
without removing it1.
 A queue is an example of a linear data structure, or more abstractly a
sequential collection. Queues are common in computer programs,
where they are used to store and process data in a certain order. For
example, queues can be used to implement buffers, schedulers,
printers, etc.
 A queue can be implemented using different data structures, such as
arrays, linked lists, or circular buffers. The choice of implementation
depends on the requirements and constraints of the problem
Uses or applications of queues

A queue is a data structure that follows the FIFO (First-In-First-Out) principle.


It means that the element that is inserted first is removed first. A queue has
four basic operations:

 Enqueue: This operation adds an element to the back of the queue. It is


similar to joining a queue at a ticket counter. The new element becomes the
last element in the queue.
 Dequeue: This operation removes and returns an element from the front of
the queue. It is similar to leaving a queue after getting a ticket. The element
that was inserted first is removed first.
 Peek or Front: This operation returns the value of the element at the front
of the queue without removing it. It is useful to check the next element to be
dequeued.
 IsEmpty or IsFull: These operations check if the queue is empty or full,
respectively. They are useful to prevent underflow or overflow errors.

These operations can be implemented using different data structures, such


as arrays, linked lists, or circular buffers

A queue is a linear data structure that follows the First In First Out (FIFO) principle,
meaning that the element that is inserted first is removed first. There are two basic
ways to implement a queue: using an array or using a linked list.

Using an array: An array is a fixed-size collection of elements of the same type. To


implement a queue using an array, we need to keep track of two indices: front and
rear. The front index points to the first element of the queue, and the rear index points
to the last element of the queue. To enqueue (insert) an element, we increment the rear
index and store the element at that position. To dequeue (remove) an element, we
return the element at the front index and increment it. We also need to check if the
queue is full or empty before performing these operations. A possible drawback of
using an array is that it may waste some space if the queue size is smaller than the
array size, or it may overflow if the queue size exceeds the array size.

Using a linked list: A linked list is a dynamic collection of nodes, where each node
contains some data and a pointer to the next node. To implement a queue using a
linked list, we need to maintain two pointers: front and rear. The front pointer points
to the first node of the queue, and the rear pointer points to the last node of the queue.
To enqueue an element, we create a new node with the element as data and make it
the next node of the rear node. We also update the rear pointer to point to the new
node.

To dequeue an element, we return the data of the front node and make the next node
of the front node as the new front node. We also update the front pointer to point to
the new front node. We also need to check if the queue is empty before performing
these operations. A possible advantage of using a linked list is that it can grow or
shrink according to the queue size, and it does not have a fixed capacity limit.

Here is an illustration of both methods:


Queue using array:

| 10 | 20 | 30 | 40 | 50 | | | |
^ ^
front rear
Enqueue 60:

| 10 | 20 | 30 | 40 | 50 | 60 | | |
^ ^
front rear

Dequeue:

| | 20 | 30 | 40 | 50 | 60 | | |
^ ^
front rear

Queue using linked list:

10 -> 20 -> 30 -> 40 -> 50


^ ^
front rear

Enqueue 60:

10 -> 20 -> 30 -> 40 -> 50 -> 60


^ ^
front rear

Dequeue:

20 -> 30 -> 40 -> 50 -> 60


^ ^
front rear

You might also like