3 DYNAMIC DATA STRUCTURES Flashcards

1
Q

What are dynamic data structures?

A

Dynamic data structures alter their structure as the data changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do dynamic data structures differ from static data structures?

A

Dynamic data structures can grow in size and adapt to changes, while static data structures have a fixed size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an example of a static data structure?

A

Array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an example of a dynamic data structure?

A

Linked list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What limitation do arrays have?

A

Their size and layout in memory are fixed at the time of creation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What must be done to extend an array’s size?

A

Create a new, larger array and copy the data from the old array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is array doubling?

A

A strategy where the size of an array doubles whenever it is expanded.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the cost of adding an element to a full array?

A

Allocate a new block of memory, copy the old values, and insert the new value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens when inserting an element in the middle of a full array?

A

Existing elements must be shifted to create space for the new value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a pointer?

A

A variable that stores the address in memory of another variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What can a pointer indicate if it is not pointing to a valid memory location?

A

A null value (None, Nil, or 0).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a linked list composed of?

A

A chain of nodes linked together by pointers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the two parts of a basic node in a linked list?

A
  • Value of any type
  • Pointer to the next node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do linked lists compare in memory usage to arrays?

A

Linked lists require more memory than arrays because they store pointers in addition to values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the null value at the end of a linked list indicate?

A

The end of the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False: Arrays can easily insert new values in the middle.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the cost of using a fixed-size array in terms of operations?

A

Expensive operations for resizing and shifting elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What analogy is used to describe the limitations of arrays?

A

A heated hotel buffet counter with a fixed number of slots.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Fill in the blank: A linked list can be visualized as a series of ______ linked by pointers.

A

nodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does each node in a linked list point to?

A

The next node in the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the primary benefit of using dynamic data structures?

A

They can grow and adapt as new data is added.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is a linked list?

A

A data structure consisting of nodes that are linked via pointers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Why do linked lists require more memory than arrays?

A

Because they store both pointers and values, leading to a higher memory cost.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How is the memory cost calculated for a linked list?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the head of a linked list?
The first node in the linked list that allows traversal of the list.
26
What is the time complexity of accessing an element in a linked list?
O(n), as it requires iterating through nodes from the head.
27
True or False: Linked lists allow for dynamic memory allocation.
True.
28
What is the advantage of linked lists over arrays?
They allow for dynamic rearrangement of data without needing contiguous memory.
29
What happens when inserting a new element into an array?
It may require reallocating memory and shifting elements.
30
What is the process of inserting a new node at the front of a linked list?
Set the new node's next pointer to the current head and update the head pointer.
31
Fill in the blank: Linked lists have a higher computing overhead than ______.
arrays.
32
What is the code structure for inserting a node after a specific node in a linked list?
new_node.next = previous.next; previous.next = new_node.
33
How do you delete a node from a linked list?
Adjust the previous node's pointer to skip the node to be deleted.
34
What is the special case when deleting the first node in a linked list?
Update the head pointer to the next node.
35
What should you do when the index for deletion or insertion is past the end of the list?
Return an error or handle it by appending to the end.
36
What does the function LinkedListInsert do?
Inserts a new node at a specified index in the linked list.
37
What is the main tradeoff when using linked lists?
Increased flexibility in data structure versus higher access overhead.
38
What is the significance of the previous pointer during insertion in a linked list?
It allows updating the next pointer of the previous node to point to the new node.
39
True or False: The nodes in a linked list must be stored in contiguous memory.
False.
40
What happens to the next pointer of a deleted node in a linked list?
It is set to null to indicate it no longer has a next node.
41
What is the time complexity for inserting an element into a linked list?
O(n) in the worst case due to traversal.
42
What is the code structure for deleting a node at a specific index?
previous.next = current.next; current.next = null.
43
Fill in the blank: Accessing an element in an array requires ______ lookup.
direct.
44
What is the purpose of the count variable in linked list operations?
To track the position of the current node during traversal.
45
What happens when the WHILE loop runs off the end of the list in the deletion function?
An error is thrown because there is nothing to delete.
46
What does the function do with the removed node's next pointer?
Sets it to null to ensure consistency and allow memory management to free unused memory.
47
How can we adapt the deletion code to use a node's value?
Update the loop condition to check for the first node with that value: WHILE current != null AND current.value != value.
48
What is the primary advantage of linked lists?
They allow insertion or removal of elements without shifting other elements in memory.
49
What is a doubly linked list?
A linked list that includes backward as well as forward pointers.
50
What additional information does a doubly linked list store compared to a singly linked list?
Pointers to both the next and previous nodes.
51
What is the structure of a DoublyLinkedListNode?
DoublyLinkedListNode { Type: Value, next: DoublyLinkedListNode, previous: DoublyLinkedListNode }.
52
What advantage does a doubly linked list provide in terms of node access?
It allows access to the previous node without traversing the entire list.
53
In what scenarios can arrays be used to store complex items?
When storing variable-size data like strings or composite data structures.
54
How can arrays and pointers be combined to manage dynamic data?
Each array bin stores a pointer to the data of interest, allowing varying sizes.
55
What is the main benefit of storing pointers in array bins?
It allows the data for each entry to vary in size and reside elsewhere in memory.
56
What is the significance of using pointers in data structures?
They enable linking across blocks of memory and creating dynamically linked structures.
57
What trade-offs should be considered when choosing data structures?
Flexibility, space requirements, efficiency of operations, and complexity.
58
What are the two data structures that will be introduced in the next chapter?
Stacks and queues.
59
Fill in the blank: A singly linked list can only traverse in _______.
one direction.
60
True or False: The next pointers in a linked list can point to arbitrary blocks of data.
False.