AQA A-Level Computer Science 7517
Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation
Fundamentals of Data Representation
Fundamentals of Computer Systems
Fundamentals of Computer Organisation and Architecture
Fundamentals of Communication and Networking
Consequences of Uses of Computing
Systematic Approach to Problem Solving
Fundamentals of Databases
Big Data
Fundamentals of Data Structures
Queues and Linear Queues
- 2 things to know
- Paper 1
Overview
Recall questions on what a queue is, its typical uses, the front and rear pointers and the working of a linear queue.
What you need to know
Answer each one before you reveal it.
Explain the problem with a linear queue that a circular queue is designed to solve.
Questions from this subtopic
Each one with the model answer underneath.
- 1
What is a queue?
Model answer
An abstract data type in which items are added at one end, the rear, and removed from the other end, the front. It is a first in, first out (FIFO) structure: the item that has been waiting longest is the next one to leave.
- 2
Give four typical uses of a queue.
Model answer
A print spooler holding documents waiting for a printer; a buffer holding keystrokes or data waiting to be processed; the ready queue of processes waiting for the processor in an operating system; and the queue of vertices still to be visited in a breadth-first search.
- 3
What do the front and rear pointers of a queue hold, and how is a queue in an array of maxSize elements initialised?
Model answer
The front pointer holds the index of the first item in the queue, and the rear pointer holds the index of the last item that was added — not the next free slot. The queue is initialised with front = 0 and rear = -1, together with a counter, size, holding the number of items currently stored, initialised to 0. A rear pointer of -1 with a size of 0 means nothing has yet been added.
- 4
Describe a linear queue.
Model answer
A queue held in an array in which items are added at successively higher indices and removed from the front. The front and rear pointers both only ever move forwards through the array, so the queue creeps along it as items are added and removed.
- 5
Describe how an item is added to a linear queue.
Model answer
First test whether the queue is full; if it is, report overflow and do not add. Otherwise increase the rear pointer by one, store the new item at the array position the rear pointer now gives, and increase the size counter by one.
- 6
Describe how an item is removed from a linear queue.
Model answer
First test whether the queue is empty; if it is, report underflow and do not remove. Otherwise take the item at the array position given by the front pointer, increase the front pointer by one so it points at the next item, and decrease the size counter by one. The item taken is returned.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Fundamentals of 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.