Course contentsShow
← Computer Science
Lesson 324 of 2,8728. Linked Data StructuresFree lesson

Introduction to Linked Lists

Understanding the linked list concept: nodes connected by pointers instead of contiguous memory like arrays.

Introduction to Linked Lists

What you'll learn: You'll understand how linked lists store data using nodes and pointers instead of contiguous memory blocks like arrays.

What is a Linked List?

A linked list is a data structure where elements (called nodes) are scattered in memory, each pointing to the next one through pointers. Unlike arrays that store elements side-by-side in contiguous memory locations, linked lists connect data through explicit links.

Think of an array like a row of mailboxes on a street—each one sits right next to the other, numbered sequentially. A linked list is more like a treasure hunt: each clue (node) tells you where to find the next clue, but the clues themselves can be hidden anywhere on the map.

Structure of a Node

Each node in a linked list typically contains:

  1. Data: The actual value you want to store (an integer, character, etc.)
  2. Pointer: A pointer to the next node in the sequence

The first node is called the head, and the last node points to NULL to signal the end of the list.

Why Not Just Use Arrays?

Arrays require contiguous memory and have a fixed size (or expensive resizing operations). Linked lists use dynamic memory allocation, so you can easily grow or shrink them by creating new nodes or removing existing ones—you only allocate exactly what you need, when you need it.

The tradeoff? Arrays give you instant access to any element by index. With linked lists, you must traverse from the head, following pointers one-by-one to reach a specific position.

Key Takeaway: Linked lists use nodes connected by pointers, allowing dynamic memory usage and flexible insertion/deletion at the cost of sequential access only.