Static And Dynamic Data Structures Flashcards

(6 cards)

1
Q

What is a static data structure?

A

A static data structure is a collection of data that has a fixed size. Its size is determined at compile time and cannot be changed during program execution. An example of this is an array. They are most frequently declared in memory in consecutive memory locations. This makes them simpler for the computer to maintain. Because the size is fixed at runtime, if the number of data items to be stored exceeds the number of memory locations, an overflow will occur.

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

What are the advantages of a static data structure?

A

No memory required for pointers so less memory required for same number of items.

Faster to access items directly (O(1)).

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

What are the disadvantages of a static data structure?

A

All memory locations must be allocated when the array is created.

This can waste memory if some memory locations are not used.

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

What is a dynamic data structure?

A

A dynamic data structure is a collection of data that can change in size at runtime. An example of this would be a linked list. When items are added to it, they’ll be placed somewhere in memory (jot necessarily next to the previous one). There’ll be a pointer saved alongside each item, which tells the computer the memory location of the next element in the list.

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

What are the advantages of a dynamic data structure?

A

No wasted memory locations.

Can grow as more data is added to the data structure.

Resources only allocated as they are needed.

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

What are the disadvantages of dynamic data structures?

A

Additional memory needed for pointers.

Can result in memory leak (if memory that is no longer needed is not returned to the heap).

Can take longer to access an item directly.

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