Deque

Projected Time

80 minutes

Prerequisites

Motivation

Deque is used as an abstract data type, also referenced as a double-ended queue. Similar to a queue, deques exist as an ordered collection of items. A deque’s nature is unrestrictive, meaning that it easily allows for adding and removing items at either end. Deques are a unique hybrid linear structure that provide the capabilities of stacks and queues in a unique data structure. Deques can be implemented with a dynamic array or with a doubly-linked list and they do not require Last In First Out (LIFO) or First In First Out (FIFO)orderings that are required by both stacks and queues. The homophone “dequeue” is used as a verb, meaning to remove from a queue.

Examples that use Deque:

Objectives

Participants will be able to:

Specific Things to Learn

Materials

Lesson

Review content from slides (TODO: add link here when available).

Common Mistakes / Misconceptions

Guided Practice

Discuss as a group how a deque differs from other data structures already reviewed. Some suggested questions to consider:

Independent Practice

Implement a deque in JavaScript, keeping in mind all methods and helper methods that define a deque. Consider performance – what happens as you call specific methods you’ve defined?

Challenge

There are many different ways to implement a deque in any language. Implement a deque a different way from what you did before, then consider how it differs. Is this second implementation better? If you get stuck, check out StackOverflow comments!

Check for Understanding

Find another person in the cohort and discuss:

Additional Reading

A-Steal Job Scheduling was briefly mentioned in the lesson as a use of deques. You can read more here.