💻 Computer Science · Topic 51 of 80

Linked Lists

Nodes link to the next node by pointers.

Interactive labFollow the idea step by step

About this topic

A linked list is a data structure in which each element, called a node, holds a value and a pointer to the next node. Unlike an array, the nodes need not be next to each other in memory. The first node is the head, and the last node points to nothing, usually written null.

To add at the front, create a new node, point it to the old head and make it the new head, which takes constant time and no shifting. To find an item, you must follow the links from the head, so access is O(n), whereas an array allows instant access by index. Doubly linked lists have both next and previous pointers, so you can move in both directions.

Linked lists are good when items are frequently inserted or removed in the middle, and they can grow without needing a big block of memory. They are used to build stacks, queues and music playlists. A common mistake is losing the rest of the list by changing a pointer before saving the next node. Another is forgetting to handle the empty list. Drawing boxes and arrows makes pointer logic much clearer.

Key ideas

  1. Easy insertion and deletion
  2. No random access
  3. Head and tail

Quick check

Use cases: where Linked Lists helps

Computing ideas run phones, search engines, games and the wider internet.

Frequently asked questions

What is Linked Lists?

Nodes link to the next node by pointers.

What will I learn in Linked Lists?

Easy insertion and deletion. No random access. Head and tail.

Is Linked Lists part of Computer Science?

Yes. It is one of 80 Computer Science topics on LearnViz HighSchoolEdu, with 3 key ideas, a live animation and a quick check.

Does the Linked Lists lab work on a phone or tablet?

Yes. The animation resizes to fit your screen and supports touch, so you can drag, tap and slide with your finger.

How should I study Linked Lists?

Read the summary and key ideas first, play with the interactive lab to see the idea in motion, then answer the quick check. If you get a question wrong, go back to the key idea it tests.

Do I need an account, and is my progress saved?

No account is needed. Marking a topic as learned is saved in your own browser, so it stays on that device and is not sent to a server.

More in Computer Science