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
What are the 6 basic operations used with stacks?
- push(item)
- pop() < removes the top item and removes it
- isFull()
- isEmpty()
- peek() < returns the top item without removing it
- size()
How can a stack be implemented as a list?
Use the list commands to refer to stack commands .e.g. append refers to push
Define overflow in terms of a stack
When you try to push an item onto a stack and it is full
Define underflow in terms of a stack
When you try to pop and item from a stack and it is empty
Define system level data structure
A data structure that dictates how computational processes are carried out
Give an example of a system level data structure
A call stack or stack frame
What is a stack frame?
A stack frame consists of an individual subprogram’s local variables, arguments and return address
How is a call stack formed?
Multiple stack frames are combined
What does a stack frame do with regards to subprograms?
It dictates how parameters and return addresses are passed to subroutines
Define a return address
The address to the point in the program execution is to return to after a subprogram has been executed
What are the two stages of running a subprogram?
Subroutine call and subroutine execution
What happens during the subroutine call?
The computer saves the parameters to the stack, saves the local variables to the stack, saves the return address to the stack and then transfer execution to the subroutine code
What happens during the subroutine execution?
The computer allocates a stack space for local variables, executes the subroutine code, retrieves the return address from the stack, pops the parameters from the stack (used in the return) and transfers execution back to the return address
Define hash table
A data structure that stores key:value pairs based on an index calculated from an algorithm
What is the purpose of a hash function?
To calculate the position of a data item within an abstract data type called a hash table dependent on the value of the data item
What is the typical format for a hash function?
Address = key % No.slots
Why is the MOD function used in hash functions?
To ensure that the address location for a key does not exceed the maximum size of the hash table
Define collision/synonym
When two values end up with the same memory location within a hash table
What is the simplest solution when a collision or synonym occurs?
To put the second item in the next available slot
Define load factor
The percentages of the hash table that has values stored in it
What is a cluster?
When the majority of items in a hash table are located in one area of the table
How does a cluster arise in a hash table?
When collisions are resolved by just placing the second item in the next available slot
What is the solution to clustering?
Introducing a skip factor
What does a skip factor do?
Spreads values involved in collisions across the hash table