Data Structures & Algorithms for Beginners - 3

Queues

 


A. Introduction to Queue

Enqueue and Dequeue: A queue is a linear data structure which models real world queues by having two primary operations

Queue Terminology:

image-20220524150439698

 

There does not seem to be consistent terminology for inserting and removing elements from queues.

1. Enqueue = Adding = Offering

image-20220531100919975

2. Dequeue = Polling

image-20220531101118912

 

B. Simple Queue Example

Instructions

 

C. When & Where

 

D. Complexity Analysis

Name of Queue InstructionBig O Notation
EnqueueO(1)
DequeueO(1)
PeekingO(1)
ContainsO(n)
RemovalO(n)
Is EmptyO(1)

 

E. Queue Example - Breadth First Search (BFS)

image-20220531103730294

image-20220531103730300

1. Pseudo-code:

 

2. Source Code for Queue