levo

Data Structures

Queues and Circular Queues

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

Overview

Recall questions on queues and their uses, front and rear pointers, enqueue and dequeue, the wasted space of a linear queue, circular queues with modulo arithmetic, telling full from empty, tracing operations, and static and dynamic queues.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is a queue?

Key term

Give three uses of a queue in a computer system.

Key term

What is wrong with a plain linear queue after it has been used for a while?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a queue?

    Model answer

    A first in, first out (FIFO) data structure: items are added at one end, the rear or back, and removed from the other end, the front or head. The item that has been waiting longest is always the next to leave, so the order of arrival is preserved.

  2. 2

    Give three uses of a queue in a computer system.

    Model answer

    A print spooler holding jobs in the order they were submitted. Keyboard and other input buffers, so that keystrokes are processed in the order typed even when the processor is busy. Process scheduling, where processes wait in a ready queue for the processor. Queues are also used for buffering streamed data and for breadth-first traversal of a graph or tree.

  3. 3

    What pointers does a queue need, and what do they hold?

    Model answer

    A front pointer, holding the position of the item that will be removed next, and a rear pointer, holding the position of the last item added (or of the next free slot, depending on convention). Many implementations also keep a count of the number of items and a record of the maximum size, which makes the full and empty tests straightforward.

  4. 4

    How do you create an empty queue?

    Model answer

    Declare an array of the maximum size, plus the front and rear pointers and, usually, a counter. Set the front pointer to 0, the rear pointer to -1 (so that the first enqueue places an item at index 0) and the counter to 0. Recording the maximum size allows the full test.

  5. 5

    Describe the enqueue operation on a linear queue.

    Model answer

    Check first whether the queue is full — if the rear pointer already holds the last index there is no room, so report the error. Otherwise move the rear pointer on by one, store the new item at the index the rear pointer now holds and increase the item count. The front pointer is not affected.

  6. 6

    Describe the dequeue operation on a linear queue.

    Model answer

    Check first whether the queue is empty - if the count is zero, or the front pointer has passed the rear pointer, report underflow. Otherwise read the item at the front pointer, increment the front pointer by one and reduce the count, then return the item read. The item's slot is left behind and is not reused.

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 Data Structures, 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.