5.1.11+Describe+the+features+and+characteristics+of+a+dynamic+data

The best way for us to look at dynamic data structures and their use is to compare it to a Static Data Structure, and look at both the advantages and disadvantages of each one, helping us make sense of when each one is used.


 * Dynamic || Static ||
 * Memory is allocated to the data structure dynamically i.e. as the program executes || Memory is allocated at compile time. Fixed size. ||
 * Disadvantage: Because the memory allocation is dynamic, it is possible for the structure to 'overflow' should it exceed its allowed limit. It can also 'underflow' should it become empty. || Advantage: The memory allocation is fixed and so there will be no problem with adding and removing data items. ||
 * Advantage: Makes the most efficient use of memory as the data structure only uses as much memory as it needs. || Disadvantage: Can be very inefficient as the memory for the data structure has been aside regardless of whether it is needed or not whilst the program is executing. ||
 * Disadvantage: Harder to program as the software needs to keep track of its size and data item at all times || Advantage: Easier to program as there is no need to check on data structures size at any point. ||

There are many situations where the number of items to be stored is not known before hand.

In this case, dynamic data structures should be used over static ones. This means that the data structured is allowed to grow and shrink as the demand for storage arises. Although, the programmer should also set a maximum size in order to help avoid memory collisions.

To better understand how this works, lets take the example of a programmer coding a "print spooler". He will have to maintain a data structure to store all the print jobs, but there is no way he can know before hand how many of these jobs there will be, so he can use a dynamic data structure to do so, since it changes based on the demand for more storage