What is a Linked List?

am20dipi

Adriana DiPietro

Posted on December 21, 2021

What is a Linked List?

Hello Programmers!✨ Let's learn about Linked Lists! Today's discussion will be an introductory, informational lesson on Linked Lists, so we will be hitting a few points:

  1. What is a Linked List?
  2. What is a Node?
  3. What is a Pointer?
  4. What does a Linked List look like?
  5. Are Linked Lists similar to Arrays?
  6. What can Linked Lists be used for?
  7. Summary + Recap
  8. Additional Resources

What is a Linked List?

A Linked List is a series of nodes connected to each other in which each node references the next node in succession.

What is a Node?

A node is a segment or piece of code that has its own value, properties.. etc. In Linked Lists each node has two main components: (1) data and (2) a pointer.

What is a Pointer?

Eternally thankful for its name, the pointer always points to the next node of the linked list. If the pointer is NULL, then that tells us that it is the last node in the list.

What does a Linked List look like?

In the simplest of possible comparisons, a Linked List resembles a caterpillar with each segment on a caterpillar representing a node.

Another fun way of thinking about a linked list is its resemblance to a conga line at party. You know -- the hilarious line of people where each member holds the shoulders of the person in front of them. We can use this comparison to think of each person's arms representing the reference to the next person, also known as the pointer.

conga line

Now, let's look at a Google-search generated image of a Linked List:

Linked List

In this unadorned rendering, we still manage to see the main components present: each node consisting of data and a pointer and the last node pointing to "NULL". These components are the basic foundation and thus, the main priorities to learn and fully understand as we continue to learn more about linked lists!

Are Linked Lists similar to Arrays?

Unlike arrays, nodes of a linked list are not stored in a particular memory location or index. This makes for slower, more difficult traversal, insertion, deletion and lookup functionality. With an array, we can easily access an array item by index; linked lists do not have indices.

On the other hand, like an array, linked lists are super efficient at appending or prepending nodes. Since the 'head' node and the 'tail' node have distinguishing attributes (the head having nothing pointing at it and the tail pointing to NULL) inserting an element at the front or the end is quite easy.

What can Linked Lists be used for?

Like we recently discovered, Linked Lists are recognized and used because of their efficient appending and prepending. Therefore, they are great to implement stacks, queues, etc.

However, let's think of an applicable, concrete example of a linked list in use on a website. We may see this in the form of an image viewer: the ability to click forward and backward through a series of images. We can also see this similarly in a music player. Another example we all probably use on a daily basis: the 'back' and 'forward' buttons in the browser.

Summary + Recap

  • A Linked List is a series of nodes.
  • A node is a segment containing two (2) components: data and a pointer.
  • A pointer references the next node in succession.
  • A Linked List must be traversed to access all nodes; meaning the beginning (the first node) is our point of access.
  • Linked Lists take up some memory because nodes contain both data AND pointers.
  • Linked Lists do not have indices.
  • The HEAD of the Linked List is the first node; nothing is pointing to the head.
  • The TAIL of the Linked List is the last node; the tail points to NULL.

Additional Resources

Here is a great resource to play with to understand the structure and operations of Linked Lists: VisuAlgo

And here is another solid resource to understand how Linked Lists are implemented in JavaScript: freeCodeCamp


✨ Thank YOU for reading along and learning with me. Please feel free to leave any comments, questions or suggestions below. And please remember to be kind to everyone because we are ALL learning here! ✨

💖 💪 🙅 🚩
am20dipi
Adriana DiPietro

Posted on December 21, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Data Structures and Algorithms: Recursion
javascript Data Structures and Algorithms: Recursion

February 2, 2024

What is a Linked List?
javascript What is a Linked List?

December 21, 2021