# Linked Lists

Learn about Linked Lists, one of the most common data structures that can be used to implement many other abstract data types..

Start## Key Concepts

Review core concepts you need to learn to master this subject

Building blocks of a linked list

The head node in a linked list

Implementing a linked list

Removing a node from the middle of a linked list

Adding a new head node in a linked list

Building blocks of a linked list

Building blocks of a linked list

A linked list is a basic data structure that consists of a linear series of nodes, each of which contains data and a link to the next node. The given illustration contains an example of a linked list. The nodes are `a1`

, `a2`

, `a3`

, `a4`

, and `a5`

respectively. Each node points to the next node. The links are indicated by green arrows.

The head node in a linked list

The head node in a linked list

The first node in a linked list is referred to as the head node. In the given example, `P-i`

is the head node.

Implementing a linked list

Implementing a linked list

A linked list exposes the ability to traverse the list from one node to another node. The starting node is considered the head node from where the list can be traversed.

Removing a node from the middle of a linked list

Removing a node from the middle of a linked list

When removing a node from the middle of a linked list, it is necessary to adjust the link on the previous node so that it points to the following node. In the given illustration, the node `a1`

must point to the node `a3`

if the node `a2`

is removed from the linked list.

Adding a new head node in a linked list

Adding a new head node in a linked list

When adding a new node to the start of a linked list, it is necessary to maintain the list by giving the new head node a link to the current head node. For instance, to add a new node `a0`

to the begining of the linked list, `a0`

should point to `a1`

.

- 1
Linked lists are one of the basic data structures used in computer science. They have many direct applications and serve as the foundation for more complex data structures. The list is comprised ...

- 2
As an example, we added values to the linked list diagram from the introduction. This linked list contains three nodes ( [...] , [...] , and [...] ). Each node in this particular list contain...

- 3
With linked lists, because nodes are linked to from only one other node, you can't just go adding and removing nodes willy-nilly without doing a bit of maintenance. #### Adding a new node Adding ...

- 4
Let's take a minute to review what we've covered about linked lists in this lesson. Linked Lists: - Are comprised of nodes - The nodes contain a link to the next node (and also the previous node ...

- 1
Let's implement a linked list in Python. As you might recall, each linked list is a sequential chain of nodes. So before we start building out the [...] itself, we want to build up a [...] clas...

- 2
With the [...] in hand, we can start building the actual linked list. Depending on the end-use of the linked list, a variety of methods can be defined. For our use, we want to be able to: - get ...

- 3
So far we can: - create a new [...] using [...] - get the head node of the list using [...] Next up, we'll define methods for our [...] class that allow us to: - insert a new head node - ...

- 4
Nice! Now we have a bunch of helpful [...] methods under our belt. The final use case we mentioned was the ability to remove an arbitrary node with a particular value. This is slightly more com...

- 5
Congratulations, you have implemented a linked list in Python! We did this by: - Defining a [...] class to hold the values and links between nodes - Implementing a [...] class to handle extern...

## How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory