Lec3Queues.pptx - DATA STRUCTURES AND ALGORITHMS Queues Momina Moetesum Dept of CS Bahria University Islamabad [email protected] 1 Queues \u2022 A

Lec3Queues.pptx - DATA STRUCTURES AND ALGORITHMS Queues...

This preview shows page 1 - 11 out of 69 pages.

Queues Momina Moetesum Dept of CS Bahria University, Islamabad [email protected] 1 DATA STRUCTURES AND ALGORITHMS
Image of page 1
Queues A queue is an ordered collection of homogenous data items such that: Items can be removed only at one end ( front of the queue) Items can be added only at the other end ( rear of the queue) Accessing the elements of queues follows a First In, First Out (FIFO) order Example: Customers standing in a check-out line in a store model a queue, the first customer in is the first customer served.
Image of page 2
Queue as an ADT A Queue is a collection of items of type T on which following operations are defined: Initialize the queue to be the empty queue . (queue q) Determine whether or not the queue is empty . (q.isEmpty()) Determine whether or not the queue is full . (q.isFull()) If Queue is not full , insert a new item from the rear of the queue. (q.enqueue(n)) If Queue is not empty , remove an item from the front of the queue. (q.dequeue()) Retrieve the value at the front of the queue (q.getFront())
Image of page 3
Enqueue and Dequeue Primary queue operations: Enqueue and Dequeue Enqueue – insert an element at the rear of the queue. Dequeue – remove an element from the front of the queue.
Image of page 4
Applications of queues Operating system Multi-user/multitasking environments, where several users or task may be requesting the same resource simultaneously Printer Queue Documents to be printed in a queue Communication Software Queues to hold information received over networks Information can be transmitted faster than it can be processed, so is placed in a queue waiting to be processed
Image of page 5
Landing and takeoff queues
Image of page 6
Queues vs. Stacks Stacks are a LIFO container: Store data in the reverse of order received Queues are a FIFO container: Store data in the order received Stacks then suggest applications where some sort of reversal or unwinding is desired. Queues suggest applications where service is to be rendered relative to order received . Stacks and Queues can be used in conjunction to compare different orderings of the same data set. From an ordering perspective, then, Queues are the “ opposite ” of stacks: Easy solution to the palindrome problem
Image of page 7
Queues vs. stack
Image of page 8
Queue Mechanism When a new Queue is created and is empty then its front and rear are at one place and at that place there will be no value. When value is added to queue it is added at the 0’s place (next block to front location) and either it is start or end, the starting block (where front and rear is -1) is empty always. Front value is always at (front+1) however rear value is at (rear).
Image of page 9
Queue Mechanism If we enque continuously, a time will come when queue become full(rear == (size-1)) .
Image of page 10
Image of page 11

You've reached the end of your free preview.

Want to read all 69 pages?

  • Fall '17
  • Tahir Iqbal
  • Void type, Standard Template Library, The Elements, Priority queue

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes