Docsity

Queues: Data Structures and Implementations, Slides of Computer Science

Partial preview of the text

Download Queues: Data Structures and Implementations and more Slides Computer Science in PDF only on Docsity!

Queues

• Linear list.

• One end is called front.

• Other end is called rear.

• Additions are done at the rear only.

• Removals are made from the front only.

Bus Stop Queue

Bus Stop front rear rear rear rear rear

Bus Stop Queue

Bus Stop front rear rear

Bus Stop Queue

Bus Stop front rear rear

Revisit Of Stack Applications

• Applications in which the stack cannot be

replaced with a queue.

 Parentheses matching.

 Towers of Hanoi.

 Switchbox routing.

 Method invocation and return.

 Try-catch-throw implementation.

• Application in which the stack may be

replaced with a queue.

 Rat in a maze.

  • Results in finding shortest path to exit.

Wire Routing

Lee’s Wire Router

start pin end pin

Label all reachable unlabeled squares 2 units

from start.

Lee’s Wire Router

start pin end pin

Label all reachable unlabeled squares 3 units

from start.

Lee’s Wire Router

start pin end pin

Label all reachable unlabeled squares 5 units

from start.

Lee’s Wire Router

start pin end pin

Label all reachable unlabeled squares 6 units

from start.

Lee’s Wire Router

start pin end pin 4

End pin reached. Traceback.

Derive From ArrayLinearList

when front is left end of list and rear is right end

  • Queue.isEmpty() => super.isEmpty()
    • O(1) time
  • getFrontElement() => get(0)
    • O(1) time
  • getRearElement() => get(size() - 1)
    • O(1) time
  • put(theObject) => add(size(), theObject)
    • O(1) time
  • remove() => remove(0)
    • O(size) time

a b c d e Docsity.com

Derive From ArrayLinearList

 to perform each opertion in O(1) time (excluding

array doubling), we need a customized array

representation.

Derive From ExtendedChain a b c d e null firstNode lastNode front rear

 when front is left end of list and rear is right end

  • Queue.isEmpty() => super.isEmpty()
    • O(1) time
  • getFrontElement() => get(0)
    • O(1) time Docsity.com