4.2 - Fundamentals of data structures Flashcards
What are the 3 features of static data structures?
They reserve memory for a set amount of data - established by the programmer in advance, even though less memory may actually be needed during program execution
They store data in consecutive memory locations
Very efficient in accessing elements directly but inefficient in memory use - memory wasted if array declared with space for 100 but only 10 added
What are the 3 features of dynamic data structures?
Memory efficient - memory capacity not fixed and can grow/shrink during run-time; constrained only by the overall memory allocation to the program
Requires memory to store pointers to the next item(s)
Accesses data by memory location rather than by index - often sequential rather than direct
What are the 5 features of a queue?
Holds an ordered sequence of items in a First In, First Out (FIFO) structure - first element added is first one removed
New elements added to the end
Remaining elements don’t move up to take up empty space when an element is removed
“Head” pointer maintained at the front to keep queue’s order - indicates the element at the front of the queue
“Tail” pointer indicates the element at the back
How is a new item added to a circular queue using the Enqueue method? (3 points)
Expression = (position of tail pointer + 1) MOD max
If the expression equals the position of the head pointer, the item is added to the circular queue
Otherwise, the queue must be full and the item cannot be added.
How is a new item added to a static priority queue using the Enqueue method? (4 points)
- isFull() method is used to check if the queue is full.
- If the queue is not full, the algorithm parses through the list from the back until an item of an equal or greater priority is found.
- As it does this, the items which are parsed through are moved back by one position to make space for the new item.
- When the item of equal or greater priority is found, the new item is added in the position behind it.
How is a new item added to a dynamic priority queue using the Enqueue method?
- isFull() method is used to check if the queue is full.
- If the queue is not full, the algorithm parses through the list from the first item onward until an item of a lower priority is found.
- Once the item of a lower priority is found, the address stored in the pointer of the item ahead is stored in a temporary variable and is changed to the address of the new value.
- The address stored in the pointer of the new item is then changed to the address stored in the temporary variable so that it links to the item of a lower priority.
What are the 3 features of a stack?
Holds an ordered, linear sequence of items
Last In, First Out (LIFO) structure - element added last will be first one removed
Only top element can be accessed - pointer must be maintained at the top
Define ‘binary tree’.
A rooted tree where every node has at most two child nodes
What are the 3 features of a binary search tree?
Nodes of left subtree - values lower than root
Nodes of right subtree - values higher than root
Can be built to speed up searching