Queues Three - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

Some concept of Data Structures are Abstract, Balance Factor, Complete Binary Tree, Dynamically, Storage, Implementation, Sequential Search, Advanced Data Structures, Graph Coloring Two, Insertion Sort. Main points of this lecture are: Queues Three, Definition, Standard Java Queue Operations, Implementation, Queue At Work, References, First in First Out, People, Documents, Waiting For the Printer

Typology: Slides

2012/2013

Uploaded on 04/30/2013

patel
patel 🇮🇳

3.8

(15)

80 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Queues
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Queues Three - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

Queues

Overview

• Definition

• Standard Java Queue Operations

• Implementation

• Queue at Work

• References

Standard Java Queue Operations

• Queue()

– Constructs an empty Queue object

• boolean isEmpty()

– Determines whether or not the queue is empty

• void enqueue( Object o )

– Adds a new element at the rear of the queue

• Object dequeue()

– Removes and returns the element from the front of the

queue

Implementation

• A queue uses a so-called circular array.

– Briefly, a circular array is created with an index variable

that increments as follows:

• I = (I+1) % MAX_SIZE

• Instance variables of a general class

– private int front

– private int rear

– private size

– private final int MAX_SIZE

– private Object[] q

Implementation (Cont’)

• public Object dequeue()

if( size == 0 )

throw new NoSuchElementException();

Object hold = q[front];

front = (front + 1) % MAX_SIZE;

size--;

return hold;

• Runtime Analysis: O(1)

Queue at Work

  • • Breadth-First Search: (pseudo code)bfs (Graph G)

{ all vertices of G are first painted white

the graph root is painted gray and put in a queue while (! Queue.isEmpty() )

{ Queue.dequeue( a vertex u )

{^ for all white successors v of u

v is painted gray Queue.enqueue(v);

} u is painted black

}^ }

Queue at Work (Cont’)

All vertices are colored white

A B C D E F

Queue at Work (Cont’)

A

B C

D E F

A

AA

B C

D E F

B C AA B C D E F C D E

AA

B C

D E F

D E F

References

• CS146 Textbook

• http://ciips.ee.uwa.edu.au/~morris/Year2/PLD

S210/queues.html

• http://renaud.waldura.com/portfolio/graph-

algorithms/#bfs