3 DYNAMIC DATA STRUCTURES Flashcards
What are dynamic data structures?
Dynamic data structures alter their structure as the data changes.
How do dynamic data structures differ from static data structures?
Dynamic data structures can grow in size and adapt to changes, while static data structures have a fixed size.
What is an example of a static data structure?
Array.
What is an example of a dynamic data structure?
Linked list.
What limitation do arrays have?
Their size and layout in memory are fixed at the time of creation.
What must be done to extend an array’s size?
Create a new, larger array and copy the data from the old array.
What is array doubling?
A strategy where the size of an array doubles whenever it is expanded.
What is the cost of adding an element to a full array?
Allocate a new block of memory, copy the old values, and insert the new value.
What happens when inserting an element in the middle of a full array?
Existing elements must be shifted to create space for the new value.
What is a pointer?
A variable that stores the address in memory of another variable.
What can a pointer indicate if it is not pointing to a valid memory location?
A null value (None, Nil, or 0).
What is a linked list composed of?
A chain of nodes linked together by pointers.
What are the two parts of a basic node in a linked list?
- Value of any type
- Pointer to the next node
How do linked lists compare in memory usage to arrays?
Linked lists require more memory than arrays because they store pointers in addition to values.
What does the null value at the end of a linked list indicate?
The end of the list.
True or False: Arrays can easily insert new values in the middle.
False.
What is the cost of using a fixed-size array in terms of operations?
Expensive operations for resizing and shifting elements.
What analogy is used to describe the limitations of arrays?
A heated hotel buffet counter with a fixed number of slots.
Fill in the blank: A linked list can be visualized as a series of ______ linked by pointers.
nodes
What does each node in a linked list point to?
The next node in the list.
What is the primary benefit of using dynamic data structures?
They can grow and adapt as new data is added.
What is a linked list?
A data structure consisting of nodes that are linked via pointers.
Why do linked lists require more memory than arrays?
Because they store both pointers and values, leading to a higher memory cost.
How is the memory cost calculated for a linked list?
K × (M + N) bytes, where K is the number of nodes, N is the size of each value, and M is the size of each pointer.