Topic 2:Data Structures Flashcards
The static implementation is less efficient at inserting new items into the list than the dynamic implementation.
Explain why this is the case.
-Not possible to simply insert item into middle of a list
-Must move all the items that come after the new process down in the array
-Moving items is time consuming/ in dynamic implementation, insertion is achieved by adjusting pointers
Explain the differences between a static and data structure.
-Static data structures have storage determined at compile time whilst a dynamic structure can grow and shrink during run time
-Static data structure can waste storage space if the number of items stored are relatively smaller than the size of the structure whereas the dynamic only uses the storage space necessary
-Static data structure has fixed size where dynamic can change
Explain two differences between a dynamic data structure and a static data structure.
-Static has a fixed size pre determined at compile time whilst a dynamic data structure grows and shrinks during run time
-Static structures waste space if the number of items stored are significantly smaller than the size of the structure
-Dynamic structure require memory to store pointers to the next item , static structures store data in consecutive memory locations
Explain how a single stack can be used in the implementation of the repeat action and undo action
Stack is used to store the pointers actions.
Each time an action is completes it is pushed onto the top of the stack
Unless it is an undo action
When repeat action is used the top item from the stack is used to indicate the action to complete, when the repeat action is used the result of the peek function is used to indicate the action is complete
When undo action is used the top item is popped from the stack of actions
State the type of error that occurs if the user tries to complete an undo action before they have completes any other action
Stack empty error// stack underflow
Explain the situation where it is more appropriate to represent a graph using an adjacency list instead of an adjacency matrix
Adjacency list appropriate when there are few edges between vertices // when graph is sparse
When edges rarely change
When the presence/absence of specific edges does not need to be
What is an array?
A data structure that can store the same data type contiguously in memory .
Has random access to all elements via it’s direct index
What is a Linked lists
A data structure that can store data non contiguously in memory.
They are dynamic .
What is the advantage of an array?
They allow random access to the elements
What is a disadvantage of an array?
They are a static data structure with a fixed sized which is set at compile time
What us a hash table?
An array that we call a hash table that is coupled in with a hash function. They compose of a primary key and a value(key value pairings).
What is a collision?
A collision occurs when different inputs produces the same hash
How can you avoid a collision?
Creating a larger hash table and using a different hash function
How do you rehash a table?
A larger hash table is created
Each existing value in the table is inserted into the new table
This new position is determined by a new hashing algorithm
Explain how a value is stored in a hash table
Hashing algorithm is applied to the key
The result is an index of where to store the value in the array
It is possible for a collision to occur when to keys provide the same hash
A collision handling method would be used and this could be using the next available memory location to store the value