Linked List

Introduction

Linked lists are a data structure that are used to store a sequence of data. They are used to store data in a linear fashion. The data is stored in nodes, which are connected to each other. The first node is called the head and the last node is called the tail. The head and tail are not connected to each other. The head is connected to the first node and the tail is connected to the last node.

Big O

The following is a table of the Big O notation for operations of linked lists and lists.

Big O notation for linked lists

Under the hood

A node is actually a class that has two properties: value and next. The value is the data that is stored in the node and the next is a reference to the next node. A node can be seen as a dictionary with two keys: value and next. For example,

You can think about a linked list as a set of nested dictionaries.

Constructor

Append

Pop

Prepend

Pop first

Get

Set

Insert

Remove

Reverse

Last updated