Skip to content

Module 2: Linked Lists (The Treasure Hunt)

📚 Module 2: Linked Lists

Course ID: DSA-104
Subject: The Treasure Hunt

Unlike an Array (which is one solid block), a Linked List is made of separate pieces called Nodes scattered all over memory.


🏗️ Step 1: The Node (The “Clue”)

A Node has two parts:

  1. Data: The information (e.g., “Alice”).
  2. Next: A pointer (The Address) to the next node.

🧩 The Analogy: The Scavenger Hunt

Imagine a treasure hunt.

  • You have a clue in your pocket.
  • It tells you where the next clue is hidden.
  • To find the 5th clue, you MUST find the 1st, 2nd, 3rd, and 4th first. You cannot skip ahead!

🏗️ Step 2: The Insertion Advantage

If you want to add a new person between Person A and Person B:

  1. You break the connection between A and B.
  2. You point A to the New Person.
  3. You point the New Person to B.
  • Nobody else in the whole line had to move! (O(1) Insertion if you are already at the spot).

🏗️ Step 3: Singly vs Doubly

  1. Singly Linked List: You can only move Forward. If you miss your stop, you have to start the whole hunt over from the beginning.
  2. Doubly Linked List: Each node has a “Next” AND a “Previous” pointer. You can move Forward and Backward.

🥅 Module 2 Review

  1. Access: O(n) - You have to follow the chain from the start.
  2. Insertion/Deletion: O(1) - Just change the pointers (No shifting required).
  3. Memory: Uses more RAM than an array because you have to store the “Address” of the next node.

:::tip Senior Tip Linked Lists are the backbone of many complex structures like Stacks, Queues, and Graphs. Master the “Pointer logic” here, and the rest of DSA will be easy! :::