What is a Linked List?
Tags: javascript, beginners, algorithms, datastructures
Published: 2021-12-21 15:19:47

Hello Programmers!:sparkles: Let's learn about <strong>Linked Lists</strong>! 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?](#what)
2. [What is a Node?](#node)
3. [What is a Pointer?](#pointer)
4. [What does a Linked List look like?](#look)
5. [Are Linked Lists similar to Arrays?](#arrays)
6. [What can Linked Lists be used for?](#use)
7. [Summary + Recap](#recap)
8. [Additional Resources](#resources)

__________________________________________________________

## What is a Linked List?<a name="what"></a>

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

## What is a Node?<a name="node"></a>

A <strong>node</strong> 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?<a name="pointer"></a>

Eternally thankful for its name, <strong>the pointer</strong> _always points_ to the <strong>next</strong> 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?<a name="look"></a>

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 <strong>the pointer</strong>. 

![conga line](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3hl89ttbmnkc8heu5w8.jpg)
 

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

![Linked List](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrmyrc7ap3nz4jdlfg2e.png)

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?<a name="arrays"></a>

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; <strong>linked lists do not have indices</strong>.  

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?<a name="use"></a>

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 name="recap"></a>

* 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<a name="resources"></a>

Here is a great resource to play with to understand the structure and operations of Linked Lists: [VisuAlgo](https://visualgo.net/en/list)

And here is another solid resource to understand how Linked Lists are implemented in JavaScript:  [freeCodeCamp](https://www.freecodecamp.org/news/implementing-a-linked-list-in-javascript/)

__________________________________________________________


:sparkles: 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! :sparkles: