Docsity

QUEUES IN DSA ALONG WITH CODE FOR BEGINNERS, Slides of Data Structures and Algorithms

Partial preview of the text

Download QUEUES IN DSA ALONG WITH CODE FOR BEGINNERS and more Slides Data Structures and Algorithms in PDF only on Docsity!

Data Structures and Algorithms

Queues

Lecture 6

Introduction to Queues

Introduction to Queues

Common Operations on Queues

- FRONT (Q ): Returns the first element on Queue Q. - ENQUEUE( x , Q ): Inserts element x at the end of Queue Q. - DEQUEUE( Q ): Deletes the first element of Q. - ISEMPTY( Q ): Returns true if and only if Q is an empty queue. - ISFULL(Q): Returns true if and only if Q is full.

Introduction to Queues (Uses)

Queue is most often used in a scenario where there is a shared resource that has to serve multiple requests but resource can handle only one request at a time

Queues Implementations

  • Static
    • Queue is implemented by an array, and size

of queue remains fix

  • Dynamic
    • A queue can be implemented as a linked

list , and expand or shrink with each enqueue

or dequeue operation.

Array Implementation of Queues

Array Implementation of Queues

How can we avoid to waste unused memory?

Circular Array?

Array Implementation of Queues

Linked List Implementation of

Queues

Linked List Implementation of

Queues

Use a pointer to store address of tail and call it rear

Linked List Implementation of

Queues

Static Implementation of Queues

Dynamic Implementation of

Queues

  • Dynamic implementation is done using

pointers.

  • FRONT: A pointer to the first element of the

queue.

  • REAR: A pointer to the last element of the

Front queue. x y z.

Rear