levo

Algorithms

Queues

  • 3 things to know
  • Component 02
Start revising · £5/month

Overview

Recall questions on queues and FIFO, adding and removing items, linear and circular queues, tracing a circular queue, telling full from empty, priority queues, breadth-first traversal, keyboard buffers, and the complexity of queue operations.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is a queue, and what does FIFO mean?

Key term

Describe the algorithm for adding an item to a queue.

Key term

What is a priority queue and how does it differ from an ordinary queue?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a queue, and what does FIFO mean?

    Model answer

    A queue is a data structure in which items are added at one end, the rear, and removed from the other end, the front. FIFO stands for first in, first out: the item that has been waiting longest is the next one served, like a queue of people at a till.

  2. 2

    Contrast a stack and a queue in one sentence each, being precise about which item leaves first.

    Model answer

    A stack removes the item added most recently, because items go on and come off the same end. A queue removes the item added earliest, because items join at the rear and leave from the front.

  3. 3

    Describe the algorithm for adding an item to a queue.

    Model answer

    Check whether the queue is full; if it is, report the error and stop. Otherwise write the new item at the position given by the rear pointer, move the rear pointer on by one, and increase the count of items held. The item now waits behind everything already in the queue.

  4. 4

    Describe the algorithm for removing an item from a queue.

    Model answer

    Check whether the queue is empty; if it is, report the error and stop. Otherwise read the item at the position given by the front pointer, move the front pointer on by one, decrease the count of items held, and return the item read.

  5. 5

    What is a linear queue and what problem does it have?

    Model answer

    A linear queue stores items in an array with the front pointer moving forward as items leave and the rear pointer moving forward as items arrive. The problem is that both pointers only ever move in one direction, so the space at the start of the array that has been vacated cannot be reused, and the queue reports itself full while much of the array is empty.

  6. 6

    How does a circular queue solve that problem?

    Model answer

    The array is treated as if its end joined back onto its beginning. When a pointer moves past the last index it wraps round to index zero, which is done by taking the remainder after dividing the incremented pointer by the array size. Vacated space at the start is therefore reused and the queue is only genuinely full when every position holds an item.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

A global variable means a variable reachable from anywhere in the program.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Algorithms, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.