4.2.2 - FoDS (Queues) Flashcards
What type of data structure is a Queue, and what does the term used to describe it mean
FIFO (First in First out)
- Meaning the first item to enter the queue is the first to leave the queue
What are the three different types of queues
- Linear
- Circular
- Priority
What are the features of a linear queue
- elements are added at the rear and removed from the front
What is the disadvantage of linear queues
- Inefficient as space is wasted when elements are dequeued.
What are the features of a circular queue
- Queue where the last position connects to the first, allowing space reuse. Prevents wasted space from dequeued elements.
What is the advantage of circular queues
- allows space reuse when items are dequeued
What are the features of a priority queue
Elements are dequeued based on priority instead of arrival order.
How many pointers do queues have and where are they placed
- 2 placed at the front and back of the queue
How do you remove an item in the middle of a queue
- You must first remove all of the items preceding it in the queue
What are the 4 key functions of a queue
- Add
- Remove
- Check if empty
- Check if Full
How do you add items to the back of the queue
- First check to see that the queue is not full
- If full report an error and stop
- Increment the back pointer and stop
- Insert new data into the location pointed to by the back pointer
How do you remove items from the front of the queue
- First check to see that the queue is not empty
- If empty report an error and stop
- Copy the data pointed by the front pointer (item to be deleted)
- Increment the front pointer and stop
When a circular queue is empty where do the front and back pointer point
To the same memory location
What is distinct about circular queues
When data items are added only the back pointer is modified
When is a circular queue full
When the back pointer points to the data location one less than the front pointer
When items in a priority queue have the same priority how are they treated
- The same as in a normal linear queue