In the last post, we have already seen some problems on Queue. In this post, we will look into little variant of traditional Queue data structure called DeQue. It’s stands for “Doubly Ended Queue” — as the name suggests and above picture depicts, it has the functionality to insert and remove elements from both front and rear ends.
Common Desirable Operations
- Insert Front — Inserts element at the front.
- Delete Front — Deletes element from the front.
- Insert Rear — Inserts element at the end.
- Delete Rear — Deletes element from the end.
- Get Front — Returns front element.
- Get Rear — Returns read element.
- Is Full — Returns True, if the deque is full.
- Is Empty — Returns True, if the deque is empty.
- Get Size — Returns length of the deque for the number of elements it contains
Let’s understand with an example —
Practical applications of Deque
- It can mimic both stack and queue operations.
- Work Stealing
Just like queue, Linked List and Arrays are common implementation of Deque as well. In the next post, I will try implementing is using Linked List and arrays.
Also, if you are also into Machine Learning/Natural Language Processing, etc domain, just like me. Make sure to check out detailed Research Paper Walkthroughs on my YT channel.