levo

Data Structures

Queues and Circular Queues

  • 3 things to know
  • Component 01

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

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

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz makes facts automatic

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

A0 + 0 gives 0.
B0 + 1 gives 1.
C1 + 1 gives 0 carry 1.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

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

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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