Thursday, November 26, 2015

Types of Data Structures


Types of Data Structures

Data structures can be classified under the following two categories:
Static: These are data structures whose size is fixed at compile time and does not grow or shrink at run time. An example of a static data structure is an array. Suppose you declare an array of size 50, but store only 5 elements in it. Therefore, the memory space allocated for the remaining 45 elements will be wasted. Similarly, if you have declared an array of size 50, but later, if you want to store 20 more elements, you will not be able to store these extra required elements because of the fixed size of an array.
 Dynamic: These are data structures whose size is not fixed at compile time and that can grow and shrink at run time to make the efficient use of memory. An example of a dynamic data structure will be a list of items for which memory is not allocated in advance. As and when items are added to the list, memory is allocated for those elements. Similarly, when items are removed from the list, memory allocated to those elements is deallocated. Such a list is called a linked list.


Arrays and linked lists are basic data structures that are used to implement other data structures, such as stacks, queues, and trees. 
An array is always a static data structure, and a linked list is always a dynamic data structure. However, the other data structures can be static or dynamic depending on whether they are implemented by using an array or a linked list.



No comments:

Post a Comment