Computer Science AS OCR
-
1-1-structure-and-function-of-the-processor as5 主题
-
1-2-types-of-processor as3 主题
-
1-3-input-output-and-storage as2 主题
-
2-1-systems-software as8 主题
-
2-3-software-development as5 主题
-
2-4-types-of-programming-language as4 主题
-
3-1-compression-encryption-and-hashing as3 主题
-
3-2-databases as3 主题
-
3-3-networks as8 主题
-
3-4-web-technologies as13 主题
-
html as
-
css as
-
css-styling as
-
javascript as
-
variables-and-constants-in-javascript as
-
outputs-in-javascript as
-
selection-in-javascript- as
-
for-loops-in-javascript- as
-
while-loops-in-javascript- as
-
strings-in-javascript- as
-
operators-in-javascript- as
-
nested-statements-in-javascript as
-
functions-and-procedures-in-javascript as
-
html as
-
4-1-data-types as8 主题
-
4-2-data-structures as4 主题
-
4-3-boolean-algebra as1 主题
-
5-1-computing-related-legislation as4 主题
-
5-2-moral-and-ethical-issues as9 主题
-
6-1-thinking-abstractly as3 主题
-
6-2-thinking-ahead as1 主题
-
6-3-thinking-procedurally as3 主题
-
6-4-thinking-logically as2 主题
-
6-5-thinking-concurrently as2 主题
-
7-1-programming-techniques as9 主题
-
8-1-standard-algorithms-and-big-o-notation as8 主题
queues as
Exam code:H046
Queues
What is a queue?
-
A queue is a First in First out (FIFO) data structure
-
Items are added to the end of the queue and removed from the front
-
Imagine a queue in a shop where customers are served from the front and new customers join the back
-
-
A queue has a back (tail) pointer and a front (head) pointer
-
Much the same as with a stack, an attempt to enqueue an item when the queue is full is called a queue overflow. Similarly, trying to dequeue an item from an empty queue is called a queue underflow.
-
A queue can be static or dynamic
-
There are three types of queues
-
Linear Queue
-
Circular Queue
-
Priority Queue
-
Main operations
|
Operation |
Description |
|---|---|
|
|
Adding an element to the back of the queue |
|
|
Returning an element from the front of the queue |
|
|
Return the value of the item from the front of the queue without removing it from the queue |
|
|
Check whether the queue is empty |
|
|
Check whether the queue is full (if the size has a constraint) |
Queue keywords
|
Keyword |
Definition |
|---|---|
|
Queue |
An abstract data structure that holds an ordered, linear sequence of items. It is a First in First out structure. |
|
FIFO |
First In First Out |
|
Static Data Structure |
Has a fixed size and can’t change at run time. |
|
Dynamic Data Structure |
Able to adapt and accommodate changes to the data inside it so it doesn’t waste as much space in memory. |
|
Pointer |
An object that stores a memory address |
Linear Queues
What are linear queues?
-
A linear queue is a data structure that consists of an array.
-
Items are added to the next available space in the queue starting from the front
-
Items are then removed from the front of the queue

Enqueue data
-
Before adding an item to the queue you need to check that the queue is not full
-
If the end of the array has not been reached, the rear index pointer is incremented and the new item is added to the queue
-
In the example below, you can see the queue as the data Adam, Brian and Linda are enqueued.




Dequeue data
-
Before removing an item from the queue, you need to make sure that the queue is not empty
-
If the queue is not empty the item at the front of the queue is returned and the front is incremented by 1
-
In the example below, you can see the queue as the data Adam is dequeued

Circular Queues
What are circular queues?
-
In A Level Computer Science, a circular queue is a static array that has a fixed capacity
-
It means that as you add items to the queue you will eventually reach the end of the array
-
When items are dequeued, space is freed up at the start of the array
-
It would take time to move items up to the start of the array to free up space at the end, so a Circular queue (or circular buffer) is implemented
-
It reuses empty slots at the front of the array that are caused when items are dequeued
-
As items are enqueued and the rear index pointer reaches the last position of the array, it wraps around to point to the start of the array as long as it isn’t full
-
When items are dequeued the front index pointer will wrap around until it passes the rear index points which would show the queue is empty

Enqueue data
-
Before adding an item to the circular queue you need to check that the array is not full
-
It will be full if the next position to be used is already occupied by the item at the front of the queue
-
If the queue is not full then the rear index pointer must be adjusted to reference the next free position so that the new item can be added
-
In the example below, you can see the circular queue as the data Lauren is enqueued.
<div class=”mb-5″ data-t
Responses