Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Linked List Data Structure | List and Array
Algorithms and Data Structures Overview
course content

Conteúdo do Curso

Algorithms and Data Structures Overview

Algorithms and Data Structures Overview

1. Introduction to ADS
2. List and Array
3. Advanced Data Structures
4. Graphs

Linked List Data Structure

A linked list is a data structure consisting of a sequence of elements called nodes, where each node contains data and a reference to the next node in the sequence.
Unlike arrays, linked lists do not have a fixed size in memory and do not store elements in contiguous memory locations. Instead, they use pointers to connect nodes, allowing for dynamic memory allocation and efficient insertion and deletion of elements.

The next section of the code illustrates this concept.

Linked list vs Array

Linked list implementation

12345678910111213141516171819
from lolviz import * from IPython.display import display_png class Node: def __init__(self, data): self.value = data self.next = None # Let's create some nodes node1 = Node(1) node2 = Node(2) node3 = Node(3) # Then let's couple them into a linked list node1.next = node2 node2.next = node3 display_png(objviz(node1))
copy

Note

Pay attention that the built-in list Python structure is not a list conceptually - the list structure is implemented as a dynamic array that can hold elements of various data types. It is similar to an array but with additional functionalities and optimizations.

In contrast to an array where we have direct access to any item, in the linked list, we have direct access only to the first item, and we can access any other item only by the chain of references.

In a linked list, what is the purpose of the "next" pointer?

Selecione a resposta correta

Tudo estava claro?

Seção 2. Capítulo 4
We're sorry to hear that something went wrong. What happened?
some-alt