Skip to content
Learn Netverks

Lesson

Step 18/36 50% through track

linked-lists-concept

Linked lists concept

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Linked lists concept: data structure and algorithm concepts with complexity analysis and interview-ready C++ examples.

Teams apply Linked lists concept in every serious DSA project—skipping it leaves blind spots in analysis and reviews.

You will apply Linked lists concept in contexts like: Interview loops, performance tuning, and foundational CS courses.

Compile and run C++17 snippets in the playground (`int main`, `std::cout`); after each run, state time and space complexity before moving on.

When you can explain the previous lesson's ideas in your own words.

A linked list chains nodes with value and next pointers. Insert/delete at known position is O(1) after finding the node; search is O(n). Unlike vectors, nodes are not contiguous.

Singly linked list

  • Head pointer to first node
  • Traversal follows next until nullptr
  • No random access—must walk from head

vs vector

Operationvectorlinked list
Index iO(1)O(n)
Insert at headO(n) shiftO(1)
Cache localityGoodPoor

Simple node struct

#include 

struct Node {
    int val;
    Node* next;
};

int main() {
    Node a{1, nullptr}, b{2, nullptr}, c{3, nullptr};
    a.next = &b; b.next = &c;
    for (Node* cur = &a; cur; cur = cur->next)
        std::cout << cur->val << " ";
    std::cout << "\n";
    return 0;
}

Important interview questions and answers

  1. Q: When use linked list?
    A: Frequent head inserts or merging sorted lists; otherwise vector often wins on modern CPUs.
  2. Q: Cycle detection?
    A: Floyd slow/fast pointers—interview classic on linked lists.

Self-check

  1. What fields does a singly linked node need?
  2. Why is index access O(n)?

Pitfall: Forgetting nullptr checks when traversing—draw pointers on paper first.

Interview prep

Insert at head?

O(1) after you have the node pointer.

Index access?

O(n) traversal—no random access.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • vs vector when?
  • O(1) insert where?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump