Data Structures Flashcards
What is a Queue?
A queue is a data structure based on an array. It is a FIFO data structure
What are Queues used for?
Queues are used by computers in keyboard buffers.
Each keypress is added to a queue and is removed once the computer has processed them.
This ensures all letters come out in the right order
What is a Linear Queue?
A linear queue has 2 pointers, a front and rear pointer
The rear pointer points to the next available position in the queue
When the queue is empty, the rear and front pointer are the same.
What is a circular queue?
When an item is dequeued from a static array, space frees up at the front of the array
It is too time consuming to move all the elements up the array, so a circular queue is implemented
If there is space at front, once the rear pointer reaches the end and an item is enqueued, it wraps to the front
If there is space at the front, once the front pointer reaches the end and an item is dequeued, it wraps to the front
What is a priority queue?
In a priority queue, items are assigned a priority
Items with the highest priority are dequeued first.
What are priority queues used for?
Processors assign time to applications according to their priority.
Applications currently in use by the user are prioritised over background applications
What is a Stack?
A data structure which is LIFO
What is the use of a Stack?
Store local variables
Store parameters
What is a Hash Table?
A table which allows data to be retrieved with a constant time complexity
What is a Collision and how are they dealt with?
A collision is when different inputs produce the same hash value, this can lead to data being overwritten.
To fix this, the value is rehashed - which is moving it to the next available place in the table.
How is a record added to a hash table?
1) A hashing algorithm is applied to a key
2) The result of the hashing algorithm is an index to show where the record should be stored in an array
3) The list is checked to see if the index is empty, if it is then the record is added
4) If it isn’t then a collision has occurred and the record must be rehashed, this involves moving it into the next available location in the table or a linked list associated with that index
How is a record searched for in a hash table?
1) Put the key of the record you are searching for into the hashing algorithm
2) Use the result of the hash function to work out the position in the table
3) If the value in the index is the one you are searching for, the algorithm stops
4) If the value is different, use the linked list overflow until its found.
What are the differences between Static and Dynamic Data Structures?
1) A static data structure is fixed in size, whereas dynamic can change - this makes dynamic more memory efficient as it only uses as much memory as it needs, whereas memory in static may go unused.
2) Static data structures store in consecutive memory locations, Dynamic stores more spread out.
3) Dynamic Data structures are faster as all you need to do is move the pointers, whereas static data structures require all data to be moved down the array.
4)Static Data structures are easier to program as there isn’t a requirement to check on the size of the data structure before accessing it
What is a heuristic technique?
A method which finds the solution in a way which isn’t the most efficient
What are the differences between Adjacency Matrices and Adjacency Lists
1) Adjacency Lists are more memory efficient, as matrices store every possible edge combination - whist lists only store existing ones
2) Adjacency Matrices are more time efficient, as you can search easily using rows/columns, Lists are far more jumbled