Unit 7 - Data Structures Flashcards
Why do abstract data types make it easier to manage data?
We do not have to be concerned with how the data is stored or how operation work on the data we just need to know the outcome
How is an abstract data type an example of encapsulation?
It self contains all of the data and the methods associated with that data within one object
How is an abstract data type an example of abstraction?
The user is not concerned with how the methods associated with the data work they just need to know how to initialise them
Give an example of an abstract data type
Queue, tree, stack, list, graph
Describe the principles of operation of a queue
When you add an item to a queue it is added at the back, you cannot add an item at the front of a queue. When an item is deleted from a queue it is not removed from the data structure the pointer just moves on to the next one
Describe how a queue works
- When an item is added it is added to the back of the queue
- There is a front pointer and an end pointer
- The item being processed is the one in the same position as front pointer
- Once it has been processed the front pointer moves up one but the item remains in the queue
What are the four operations performed on a queue?
- enQueue()
- deQueue()
- isEmpty()
- isFull()
What is the front pointer?
It indicates which item is next to be processed
What is the rear pointer?
Indicates which item was last added to the queue
T/F: Queues do not shuffle data
True
What is the disadvantage of linear queues?
They only have a finite number of blocks in the queue and once they have been filled no more can even be added because queues do not shuffle or remove data
How do circular queues work?
In a circular queue the front and rear pointers are able to double back on themselves meaning that they can loop around the queue and write over data in previous slots that has already been processed even though it cannot be deleted
What function enables you to determine the location of an item in a circular queue from the beginning?
The MOD function
How do priority queues work without shuffling data and still using the ‘first in first out’ principle?
They work by organising the elements added into priorities which are effectively sub-queues. This means that the first in first out principle does still apply but just within a priority
Why can you not add infinitely to any data structure?
Because the memory heap for that data structure will always have a finite size
Describe how to find the position of an item in a circular queue
(Position of front pointer + Number of items in the queue) + (Change in time/Time taken to deQueue an item) (%)
Define memory heap
A section of memory that is reserved for use by a data structure
Define array
A set of related data items stored under a single identifier
What are the 9 programming operations used on lists?
- isEmpty()
- append(item)
- remove(item)
- count(item)
- len(list)
- index(item)
- insert(pos, item)
- pop() < last item in the list
- pop(pos)
Why is a list an abstract data type?
We can perform operations on a list and on the data in the list without needing to know how they work .e.g. append
How does a memory heap contribute to the management of a list?
A memory heap is allocated to the list and when an item is added it is added to a location designated to the heap assigned to the list, when it is removed the empty location is returned to the heap
Why is a stack useful?
When using recursive algorithms it is used to unravel the recursion when the function is returned .e.g. depth-first searches of trees
Define stack
A data structure where the last item added is the first item removed
Why is a stack useful for reversing strings?
The order of insertion is the opposite of the order of removal