# What Is Dequeue in Data Structure How It Is Represented in Memory?

//

Angela Bailey

What Is Dequeue in Data Structure How It Is Represented in Memory?

A dequeue, also known as a double-ended queue, is a linear data structure that allows insertion and deletion of elements from both ends. It combines the properties of both stacks and queues.

## Representation of Dequeue in Memory

In memory, a dequeue can be represented using various data structures. One common representation is through an array.

Array Representation:

When using an array to represent a dequeue, we allocate a fixed-size array and maintain two pointers – front and rear. The front pointer refers to the first element of the dequeue, while the rear pointer points to the last element.

The following HTML code demonstrates how an array representation of a dequeue looks like:

<p>Array Representation:</p>
<ul>
<li>Front Pointer: 0</li>
<li>Rear Pointer: 5</li>
<li>[2, 5, 7, _, _, 9]</li>
</ul>

The above representation shows that the front pointer is at index 0, the rear pointer is at index 5, and the elements present in the dequeue are [2, 5, 7, _, _, 9]. The underscore (_) represents empty spaces in memory.

### Operations on Dequeue

A dequeue supports various operations such as:

• Insertion at Front: This operation adds an element to the front of the dequeue. It involves moving the front pointer to the previous index and assigning the new element.
• Insertion at Rear: This operation adds an element to the rear of the dequeue.

It involves moving the rear pointer to the next index and assigning the new element.

• Deletion from Front: This operation removes an element from the front of the dequeue. It involves moving the front pointer to the next index.
• Deletion from Rear: This operation removes an element from the rear of the dequeue. It involves moving the rear pointer to the previous index.

The following HTML code demonstrates how these operations can be represented visually:

<h3>Operations on Dequeue</u></h3>
<ul>
<li>Insertion at Front: [10, 2, 5, 7, _, _, 9]</li>
<li>Insertion at Rear: [10, 2, 5, 7, _, _, 9, 3]</li>
<li>Deletion from Front: [2, 5, 7, _, _, 9, 3]</li>
<li>Deletion from Rear: [2, 5, 7, _, _, _]</li>
</ul>

The above representation visually shows the effect of each operation on the dequeue. For example, after the insertion at the front, the dequeue becomes [10, 2, 5, 7, _, _, 9]. Similarly, after the deletion from the rear, the dequeue becomes [2, 5, 7, _, _, _].

By using appropriate data structure representations and visual elements in HTML, we can effectively understand and explain complex concepts like dequeues in data structures.