Page 37 - Data Structures Interactive Book
P. 37

Chapter 4



                 4.1   Introduction to Linked Lists

                       Linked lists are dynamic data structures that consist of nodes connected by pointers.

               Unlike  arrays,  which  store  elements  in  contiguous  memory  locations,  linked  lists  store

               elements in separate memory blocks, with each node containing data and a pointer to the
               next node. This structure allows efficient insertion and deletion operations, as elements can

               be  added  or  removed without  shifting  other  elements.  Linked  lists  are  particularly useful

               when the size of the data set is unknown or changes frequently.


                     4.1.1  Definition and Characteristics


                       A linked list is a sequence of nodes, where each node contains two parts:

                       •  Data field: stores the actual value.

                       •  Pointer field: stores the address of the next node.

                       Characteristics of linked lists include dynamic memory allocation, efficient insertion

               and deletion, and sequential access. However, they require more memory than arrays due to
               the storage of pointers.


                     4.1.2  Comparison with Arrays


                       Arrays  provide  constant-time  random  access  but  have  fixed  size  and  inefficient

               insertion/deletion.  Linked  lists,  on  the  other  hand,  allow  dynamic  resizing  and  efficient
               insertion/deletion  but  require  sequential  traversal  to  access  elements.  Thus,  the  choice

               between arrays and linked lists depends on the application requirements.


                     4.1.3  Memory Representation


                       In memory, each node of a linked list is allocated separately, and nodes are connected
               through pointers. This non-contiguous arrangement enables flexibility but increases overhead

               due to pointer storage.






                                                             37
   32   33   34   35   36   37   38   39   40   41   42