5 Levels of Using deque in Python — Explaining with Real Interview Questions

Using built-in doubly-linked lists to implement stacks and queues

Yang Zhou
TechToFreedom

--

Image from Wallhaven

Stacks and queues are significant data structures used in many programming scenarios.

Of course, it needs some time to master them. But the good news is, in Python, you don’t need to implement them by yourself.

There is a built-in object called deque, which is implemented as a doubly-linked list under the hood, providing all the necessary features for you to use it as a stack or a queue.

This article summarises the syntax, tricks and usages of deque in 5 levels of difficulty, especially the last 2 levels use real interview questions about stacks and queues to show you how to leverage it on an algorithm interview.

1. Creating Doubly-Linked Lists Using deque

Essentially, a Python’s built-in deque object is a doubly-linked list implemented by C.

You can give a deque an iterable object and it will be converted into a doubly linked list under the hood.

--

--