Fundamentals of Data Structures Flashcards
What is a queue?
A FIFO (First in, first out) data structure
What is a stack?
A LIFO (Last in, first out) data structure
What’s a graph?
A data structure made up of nodes which have a cyclical structure
What is a tree?
A data structure made up of nodes which isn’t cyclical.
Usually hierarchical.
The top level is known as the “root node”
The bottom level nodes are known as “leaf nodes”
What is a hash table?
A data structure where a hash function is used to mark the position in the table where data should be stored.
This allows us to access data directly rather than a search
What is a dictionary?
A collection of key-value pairs in which the value is accessible via the associated key
What is a dynamic data structure?
A data structure that changes in size to store their contents.
What is a static data structure?
A method of storing data where the amount of data stored (and memory used t store it) is fixed
Discuss the advantages and disadvantages of dynamic data structures compared to static data structures.
Advantages of dynamic:
There’s no wasted memory, static allocates at creation dynamic allocates as it’s needed.
No limit on the number of items which can be added, static has a finite/fixed limit.
Disadvantages of dynamic:
Can take longer to add a new item to the structure, because it has to allocate memory.
Can cause a memory leak, if memory that’s no longer needed isn’t returned to the heap
What is a linear queue?
Organised as a list or line of data
Describe the steps involved in adding an item to a linear queue that has been implemented as a static data structure using an array
Check that the queue is not already full;
(if it isn’t) then add 1 to the value of the rear pointer; [increment address]
then add the new item to the position indicated by the rear pointer;
What is a priority queue?
Queue where each item has a priority, and items are kept sorted with the highest priority item in front (priority is signified as subscript numbers)
What is a circular queue?
The last node is connected back to the first node in nature
Its static; has a limited number of elements
What is meant by the term ‘push’?
A process which adds an item to a data structure typically to a stack.
What is meant by the term ‘pop’?
A process which removes an item from a data structure typically from a stack.
What is meant by the term ‘peek’?
A process which allows you to inspect a data structure and returns the item at the front or top without removing it.
What is a weighted graph?
A graph in which each edge has a value associated with it
What is an Adjacency Matrix used for?
To represent a graph by listing each node and indicating where there is an edge between pairs.
What is an Adjacency List?
A collection of lists used to represent a finite graph, where each list escribes the set of adjacent nodes in the graph.
How do you make an Adjacency Matrix?
Look at graph, if there is an edge between them, put a 1.
If not, put a 0.
If it’s weighted:
Instead of 1, put the weight. If no edge, put infinity symbol.
On directed graph only do when you could go in that direction.
When is it good to use an adjacency list instead of an adjacency matrix?
When the graph is sparse.
When edges are rarely changed.
What is a rooted tree?
A tree in which one node has been designated as the root and ever edge is directed away from it.
What is binary tree?
A tree where each node can only have 0, 1 or 2 leaf nodes
Describe the steps involved in adding a record to a hash table
Take your key value and put it through a hashing algorithm.
The hash number (the result) is the location in the table where the data should be stored.
If the location found isn’t empty:
A hash collision has occurred, and you should move onto the next available location.
With large lists, a hash cluster may occur where many data items aren’t in the correct location as per the hashing algorithm. Instead, you can create a linked list and store multiple pieces of data in the same location