CSE NotesCSE Notes
Simplifying Complexity

A linked list is a linear data structure where elements, called nodes, are connected through pointers. Each node contains two parts: the data and a reference (or pointer) to the next node in the sequence. Here’s a breakdown of the key concepts:

Components of a Linked List

  1. Node: The basic unit of a linked list, which contains:
    • Data: The value or information the node holds.
    • Next: A pointer/reference to the next node in the list.
  2. Head: The first node in the linked list. It is used to access the entire list.
  3. Tail: The last node in the linked list, which points to null (or None in Python) indicating the end of the list.

Types of Linked Lists

  1. Singly Linked List: Each node points to the next node; traversal is one-way.
  2. Doubly Linked List: Each node points to both the next and the previous node; allows traversal in both directions.
  3. Circular Linked List: The last node points back to the first node, forming a circle.

Basic Operations

  1. Insertion: Adding a new node to the list (at the beginning, end, or a specific position).
  2. Deletion: Removing a node from the list (by value or position).
  3. Traversal: Visiting each node in the list to access or display the data.
  4. Search: Finding a node with a specific value.

Advantages

  • Dynamic size: Can grow or shrink as needed.
  • Efficient insertions/deletions: Especially at the beginning or end.

Disadvantages

  • No direct access: Unlike arrays, nodes cannot be accessed directly by index.
  • Extra memory: Requires more memory for storing pointers.