{"componentChunkName":"component---src-templates-blog-post-jsx","path":"/blogs/linkedLists","result":{"data":{"blog":{"frontmatter":{"title":"LINKED LISTS","thumbnail":"blog21","date":"November 25, 2020","dsaCppCodeFile":null},"excerpt":"<div class=\"my-2 p-2\">\n              <p>\n                In this blog post will study what is linked lists, arrays vs\n                linked lists, advantages and disadvantages of linked lists,\n                operations, types and applications of linked lists.\n              </p>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Definition</h4>\n              <div class=\"m-2\">\n                <p>\n                  A linked list is a linear data structure used for storing\n                  collections of data. It consists of nodes where each node\n                  contains a data field and a reference(link) to the next node\n                  in the list. <br />\n                  A linked list has the following properties:\n                </p>\n                <ul class=\"pl-4\">\n                  <li>Successive elements are connected by pointers.</li>\n                  <li>The last element points to NULL.</li>\n                  <li>\n                    Can grow or shrink in size during execution of a program.\n                  </li>\n                  <li>It's a memory efficient DS.</li>\n                </ul>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Arrays vs Linked Lists</h4>\n              <ul class=\"pl-4\">\n                <li>\n                  Elements are stored consecutively(contiguous memory block) in\n                  arrays whereas it is stored randomly in Linked lists.\n                </li>\n                <li>\n                  Arrays are of fixed size. In contrast, Linked lists are\n                  dynamic and flexible, can expand and contract its size.\n                </li>\n                <li>\n                  In an array, memory is assigned during compile time while in a\n                  Linked list it is allocated during execution or runtime.\n                </li>\n                <li>\n                  In addition memory utilization is inefficient in the array.\n                  Conversely, memory utilization is efficient in the linked\n                  list.\n                </li>\n                <li>\n                  Accessing an element in an array is fast(using index or\n                  subscript), while Linked list takes linear time, so it is\n                  quite a bit slower.\n                </li>\n              </ul>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Advantages & Disadvantages</h4>\n              <div class=\"m-2\">\n                <p class=\"mb-0\"><strong>Advantages</strong></p>\n                <p>\n                  The main advantage of linked lists is that they can be\n                  expanded in constant time. To create an array, we must\n                  allocate memory for a certain number of elements. To add more\n                  elements to the array when full, we must create a new array\n                  and copy the old array into the new array. This can take a lot\n                  of time.\n                </p>\n                <p class=\"mb-0\"><strong>Disadvantages</strong></p>\n                <p>\n                  The main disadvantage of linked lists is access time to\n                  individual elements. Array is random-access, which means it\n                  takes O(1) to access any element in the array. Linked lists\n                  take O(n) for access to an element in the list in the worst\n                  case. Another advantage of arrays in access time is spacial\n                  locality in memory.\n                </p>\n                <p>\n                  Sometimes linked lists are hard to manipulate. If the last\n                  item is deleted, the last but one must then have its pointer\n                  changed to hold a NULL reference. This requires that the list\n                  is traversed to find the last but one link, and its pointer\n                  set to a NULL reference.\n                </p>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Standard operations</h4>\n              <ol class=\"pl-4\">\n                <li>\n                  <strong>Traverse: </strong> Iterate through the nodes in the\n                  linked list starting from the head node.\n                </li>\n                <li>\n                  <strong>Insert: </strong> Add new node at front/rear or any\n                  specified posistion.\n                </li>\n                <li>\n                  <strong>Delete: </strong> Delete a node at front/rear or any\n                  specified posistion.\n                </li>\n                <li>\n                  <strong>Count: </strong> To find the no of nodes in linked\n                  list.\n                </li>\n                <li>\n                  <strong>Display: </strong> Traverse the linked list and\n                  display the data of each node.\n                </li>\n              </ol>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Types</h4>\n              <ol class=\"pl-4\">\n                <li>Singly Linked Lists</li>\n                <li>Doubly Linked Lists</li>\n                <li>Circular Linked Lists</li>\n              </ol>\n              <p class=\"text-muted\">\n                <em>We will study each of this type in separate blog posts.</em>\n              </p>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Applications</h4>\n              <ul class=\"pl-4\">\n                <li>Can be used to implement stacks, queues and graphs.</li>\n                <li>Maintaining directry names.</li>\n                <li>Previous and next page in web browser.</li>\n                <li>Undo and redo in editors.</li>\n              </ul>\n            </div>\n            <div class=\"my-2 p-2\">\n              <strong>Similar posts:</strong>\n              <a href=\"/blogs/singlyLinkedLists\">Singly Linked Lists</a> |\n              <a href=\"/blogs/circularLinkedLists\">Circular Linked Lists</a> |\n              <a href=\"/blogs/doublyLinkedLists\">Doubly Linked Lists</a>\n            </div>\n","html":"<div class=\"my-2 p-2\">\n              <p>\n                In this blog post will study what is linked lists, arrays vs\n                linked lists, advantages and disadvantages of linked lists,\n                operations, types and applications of linked lists.\n              </p>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Definition</h4>\n              <div class=\"m-2\">\n                <p>\n                  A linked list is a linear data structure used for storing\n                  collections of data. It consists of nodes where each node\n                  contains a data field and a reference(link) to the next node\n                  in the list. <br />\n                  A linked list has the following properties:\n                </p>\n                <ul class=\"pl-4\">\n                  <li>Successive elements are connected by pointers.</li>\n                  <li>The last element points to NULL.</li>\n                  <li>\n                    Can grow or shrink in size during execution of a program.\n                  </li>\n                  <li>It's a memory efficient DS.</li>\n                </ul>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Arrays vs Linked Lists</h4>\n              <ul class=\"pl-4\">\n                <li>\n                  Elements are stored consecutively(contiguous memory block) in\n                  arrays whereas it is stored randomly in Linked lists.\n                </li>\n                <li>\n                  Arrays are of fixed size. In contrast, Linked lists are\n                  dynamic and flexible, can expand and contract its size.\n                </li>\n                <li>\n                  In an array, memory is assigned during compile time while in a\n                  Linked list it is allocated during execution or runtime.\n                </li>\n                <li>\n                  In addition memory utilization is inefficient in the array.\n                  Conversely, memory utilization is efficient in the linked\n                  list.\n                </li>\n                <li>\n                  Accessing an element in an array is fast(using index or\n                  subscript), while Linked list takes linear time, so it is\n                  quite a bit slower.\n                </li>\n              </ul>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Advantages & Disadvantages</h4>\n              <div class=\"m-2\">\n                <p class=\"mb-0\"><strong>Advantages</strong></p>\n                <p>\n                  The main advantage of linked lists is that they can be\n                  expanded in constant time. To create an array, we must\n                  allocate memory for a certain number of elements. To add more\n                  elements to the array when full, we must create a new array\n                  and copy the old array into the new array. This can take a lot\n                  of time.\n                </p>\n                <p class=\"mb-0\"><strong>Disadvantages</strong></p>\n                <p>\n                  The main disadvantage of linked lists is access time to\n                  individual elements. Array is random-access, which means it\n                  takes O(1) to access any element in the array. Linked lists\n                  take O(n) for access to an element in the list in the worst\n                  case. Another advantage of arrays in access time is spacial\n                  locality in memory.\n                </p>\n                <p>\n                  Sometimes linked lists are hard to manipulate. If the last\n                  item is deleted, the last but one must then have its pointer\n                  changed to hold a NULL reference. This requires that the list\n                  is traversed to find the last but one link, and its pointer\n                  set to a NULL reference.\n                </p>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Standard operations</h4>\n              <ol class=\"pl-4\">\n                <li>\n                  <strong>Traverse: </strong> Iterate through the nodes in the\n                  linked list starting from the head node.\n                </li>\n                <li>\n                  <strong>Insert: </strong> Add new node at front/rear or any\n                  specified posistion.\n                </li>\n                <li>\n                  <strong>Delete: </strong> Delete a node at front/rear or any\n                  specified posistion.\n                </li>\n                <li>\n                  <strong>Count: </strong> To find the no of nodes in linked\n                  list.\n                </li>\n                <li>\n                  <strong>Display: </strong> Traverse the linked list and\n                  display the data of each node.\n                </li>\n              </ol>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Types</h4>\n              <ol class=\"pl-4\">\n                <li>Singly Linked Lists</li>\n                <li>Doubly Linked Lists</li>\n                <li>Circular Linked Lists</li>\n              </ol>\n              <p class=\"text-muted\">\n                <em>We will study each of this type in separate blog posts.</em>\n              </p>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Applications</h4>\n              <ul class=\"pl-4\">\n                <li>Can be used to implement stacks, queues and graphs.</li>\n                <li>Maintaining directry names.</li>\n                <li>Previous and next page in web browser.</li>\n                <li>Undo and redo in editors.</li>\n              </ul>\n            </div>\n            <div class=\"my-2 p-2\">\n              <strong>Similar posts:</strong>\n              <a href=\"/blogs/singlyLinkedLists\">Singly Linked Lists</a> |\n              <a href=\"/blogs/circularLinkedLists\">Circular Linked Lists</a> |\n              <a href=\"/blogs/doublyLinkedLists\">Doubly Linked Lists</a>\n            </div>"},"thumbnail":{"childImageSharp":{"fluid":{"tracedSVG":"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='225'%20viewBox='0%200%20400%20225'%20preserveAspectRatio='none'%3e%3cpath%20d='M24%2091l-1%2010-1%209h23v-7c0-3%202%200%203%203s2%204%204%204%202%200%202-7l1-10c0-2%200-2-2-2-3%200-3%200-3%203v4l-2-4c-1-3-2-3-4-3s-3%201-3%208l-1%207v-8c0-7%200-8-2-8-1%200-2%200-1%201l-1%201h-1v12h-7v-7c0-5-1-7-2-7l-2%201m33%200l-2%2010v9h2c3%200%203%200%203-4v-3l3%203c2%204%202%204%204%202h2c0%202%206%203%2011%201%204-1%203-4-2-4s-5-2%200-3c4-1%203-3-1-4-4%200-4-2%201-3%204%200%205-1%205-3l-6-1-7%201h-2c-2-2-2-2-4%201-3%203-4%203-4%200%201-3-2-4-3-2m30%200c-3%200-3%201-3%207-1%2012-1%2012%202%2012%206%200%2011-6%2011-13%200-2-4-7-6-7l-4%201m19%206l-1%2010v3h8l10-1h2c8%204%2014-4%207-10l-3-4%202%201c1%202%202%202%204%201%205-2%205-2%205%206%200%207%200%207%202%207%203%200%203%200%203-7s1-8%203-8c3%200%203-5%200-4a690%20690%200%2001-12%202h-1c-1-3-7-3-9%200-3%203-2%207%201%209%204%203%204%204%200%204-2-1-3-1-4%201V90h-2c-2%200-2%201-3%205%200%208-1%209-5%209h-3v-7c0-6%200-7-2-7s-2%201-2%207m47-4c-3%203-2%206%201%208%204%204%204%205%200%205-4-1-5%202-1%203%203%201%206%201%208-1%203-3%203-5-1-8l-3-5%201%201c1%202%204%202%205%200%201-5-8-7-10-3m115%209c-3%203-5%2013-3%2017%201%202%204%203%205%201%201-1-1-9-3-10-4-1%202-9%208-9%207%200%209%205%206%2011-2%205-2%208%200%209%204%201%207-8%204-9l-1-4c0-8-10-12-16-6m31%204l-1%208v7h17l-5%205a67%2067%200%2000-19%2036l-2%2010c0%203-1%203%208-7%205-8%2015-12%2015-8%200%202%201%203%203%203s3-1%201-2l-1-3h4c3%200%202%201%200%204l-2%204v3h-17v7c0%206%200%207-2%208-3%202-3%203%200%203%202%200%203%204%201%206l-6%201c-9%200-11-4-7-9l2-5c0-3-8%206-8%2010-1%203-1%203-10%204-8%200-8%200-8%202s1%203%205%203c5%200%206%200%204%205-1%202%201%202%2048%202h49l1-4c1-2%202-3%205-3%205-1%205-4%200-5h-3v-14c0-14-1-21-4-21l-2-2-1-2c-7-1-7-4-3-12%207-13%207-17%200-22-4-3-5-4-5-8l-1-4c-1-1-1%201-1%204%200%205%200%205-2%204l-23%201-3%201v-10l-14-1-13%201m2%208v6h22v-13h-22v7M24%20124l-1%2010v9l3-1c5%200%207-2%208-5%202-4%202-9%200-12-1-2-7-3-10-1m18%202l-4%209-2%207h3l3-1c1-2%205-3%205-1s4%203%205%202l-3-17c-1-3-6-3-7%201m11%200c0%203%200%203%202%203%202-1%202-1%202%206s0%207%203%207c2%200%202%200%202-7%200-6%200-7%203-7l2-3c0-2-1-2-7-2h-7v3m20%200c-2%202-6%2015-6%2016h3l3-1c0-3%204-2%204%200%201%202%204%202%205%201s-2-16-3-18c-2-2-5-1-6%202m21%200c-3%203-3%205%202%209l4%203h-4c-3%200-3%200-3%202%200%203%208%203%2010%200s1-6-2-8l-3-4h1c1%202%205%203%205%201l3-1c2%200%202%200%202%207s0%207%202%207%203-1%203-2c0-11%200-12%202-12l2-3c0-2-1-2-6-2-6%200-7%200-7%202h-2c-3-3-7-2-9%201m27-2l-2%209c0%209%200%209%202%209l3-3%201-3%201%203c2%203%203%203%205%202v-3c-1-3-1-4%201-6v-6c-2-3-8-4-11-2m14%201v15c1%203%208%203%2010%200%203-4%203-17%200-17-2%200-3%203-3%2010%200%204-1%206-3%205v-8c0-6%200-7-2-7l-2%202m16%200c-3%204-4%2011-2%2014%202%204%207%204%2010%201s1-7-2-3c-3%203-5-1-3-7%201-3%204-4%203-1-1%202%200%202%202%202l3-1c0-1%201-2%203-2s2%200%202%207%200%207%203%207l2-1c-1-5%200-13%202-13l2-3c0-2-1-2-6-2-7%200-7%200-7%202v2l-2-2c-3-3-7-3-10%200m27%201v15l5%201c5%200%207-3%207-11%200-7%200-8-2-8-1%200-2%201-3%207-1%209-2%209-3%200%200-6%200-7-2-7-1%200-2%201-2%203m15-2l-2%209v9h2c2%200%203-1%203-3l1-3%201%203c2%203%203%203%205%202v-3c-1-2-1-4%201-6%201-3%201-5-1-7-1-2-8-3-10-1m14%201l-1%2010v7h7c6%200%206%200%206-2%200-3%200-3-4-3-5%200-5-2-1-2%204-1%204-5%200-5l-3-1%204-1c3%200%204%200%204-2%201-3%200-3-6-3-5%200-6%200-6%202m63%2016l1%209h12v-18h-13v9m55%2016c0%201-1%202-3%202s-2%201-2%204v3h6c9%200%209%200%208%207l1%208v2l-1%203c0%204%200%204%205%204%207%201%2010-1%207-7v-5l-1-3-3-5-1-3h-1v-2l-3-5c-1-2-3-3-7-4l-5-2v3m-52%207l-1%205c0%203%200%204-1%203%200-4-2-3-3%200l2%204%202%203%203%201c2%200%202%200%202-3%200-2%200-3%202-3s2-1%202-4l-1-4-1%203c0%204-2%203-2-2-1-3-1-4-4-3'%20fill='%23d3d3d3'%20fill-rule='evenodd'/%3e%3c/svg%3e","aspectRatio":1.7699115044247788,"src":"/static/2d81aeabe7f02db5b226bf6a0c3c905f/ee604/blog21.png","srcSet":"/static/2d81aeabe7f02db5b226bf6a0c3c905f/69585/blog21.png 200w,\n/static/2d81aeabe7f02db5b226bf6a0c3c905f/497c6/blog21.png 400w,\n/static/2d81aeabe7f02db5b226bf6a0c3c905f/ee604/blog21.png 800w,\n/static/2d81aeabe7f02db5b226bf6a0c3c905f/f3583/blog21.png 1200w,\n/static/2d81aeabe7f02db5b226bf6a0c3c905f/e4d72/blog21.png 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"pageContext":{"blog":"linkedLists","thumbnail":"thumbnails/blog21.png"}},"staticQueryHashes":["2987289216","63159454"]}