What is a Linked List?
๐ก Concept Name
Linked List โ A collection of elements, called nodes, where each node stores data and a link (or reference) to the next node in the chain. In .NET, this is implemented as LinkedList<T>
.
๐ Quick Intro
Linked lists are flexible data structures that make it easy to add or remove elements on the fly. Instead of keeping everything packed in a row like an array, each value (node) points to the nextโso the list can grow or shrink as needed, with no wasted space or awkward shifting.
๐ง Analogy / Short Story
Imagine a relay race, where each runner hands the baton to the next person. You donโt need to know how many runners are in the race; you just follow the baton from one to another. Thatโs a linked listโeach โrunnerโ (node) knows who comes next, making it easy to add, remove, or rearrange people mid-race.
๐ง Technical Explanation
- ๐ Each node contains data and a reference to the next node (and optionally, the previous one in a doubly linked list).
- ๐ No fixed sizeโlinked lists grow and shrink dynamically, one node at a time.
- โก Insertion and removal (especially at the start or end) are fastโno shifting large blocks of data.
- โ Direct access by index is not supported; you must walk from the start to find an element (linear time).
- ๐ You can use singly linked lists (next pointer only), doubly linked lists (next and previous pointers), or even circular lists.
๐ฏ Purpose & Use Case
- โ When your program needs to frequently add or remove items from anywhere in the list.
- โ Great for building stacks, queues, or graph adjacency lists.
- โ Perfect when the total number of elements isn't known in advance and can change at any time.
๐ป Real Code Example
// Using LinkedList in C#
var shoppingList = new LinkedList<string>();
shoppingList.AddLast("Eggs");
shoppingList.AddLast("Milk");
shoppingList.AddFirst("Bread");
// Print out each item in the shopping list:
foreach (string item in shoppingList)
{
Console.WriteLine(item);
}
// Output: Bread, Eggs, Milk

โ Interview Q&A
Q1: What makes a linked list different from an array?
A: Linked lists connect elements with pointers, not indexesโmaking them dynamic and flexible.
Q2: Which types of linked lists exist?
A: Singly linked, doubly linked, and circular linked lists.
Q3: Can you jump straight to the 5th element in a linked list?
A: No, you must walk through each node in sequence.
Q4: How fast is inserting at the head of a linked list?
A: O(1)โinstant!
Q5: When is a linked list better than an array or list?
A: When you need lots of inserts/removals, not random access.
Q6: Whatโs the memory overhead for linked lists?
A: Each node stores both the value and a pointer (reference), which takes extra memory.
Q7: How do you use linked lists in .NET?
A: With the LinkedList<T>
class.
Q8: How fast is traversal in a linked list?
A: O(n)โyou must visit each node to find what you want.
Q9: Is LinkedList<T>
in .NET generic?
A: Yesโitโs type-safe and works with any type.
Q10: Is memory usage higher than arrays?
A: Yes, because each node stores an extra reference or two.
๐ MCQs
Q1. What is a linked list?
- A sequence of nodes with pointers
- An indexed array
- A table of rows
- A stack
Q2. Which operation is fast in a linked list?
- Search
- Index lookup
- Insertion/deletion
- Sorting
Q3. What is the time complexity to insert at head?
- O(n)
- O(log n)
- O(1)
- O(n^2)
Q4. Which has more memory overhead?
- Array
- Linked list
- Both equal
- Depends
Q5. What is a node?
- A class
- A data cell
- An element with data and pointer
- An index
Q6. Can LinkedList<T> be iterated with foreach?
- No
- Yes
- Only via index
- Only in arrays
Q7. What type of memory does a linked list use?
- Stack
- Heap
- Global
- Cache
Q8. What is LinkedList<T> in .NET?
- Stack implementation
- Array list
- Generic linked list class
- List adapter
Q9. Can you add at both ends in LinkedList<T>?
- No
- Yes
- Only at front
- Only at end
Q10. Is indexing supported directly?
- Yes
- No
- With extension method
- Only in C++
๐ก Bonus Insight
Use LinkedList<T>
when your app is all about quick insertions and deletions, not speed-searching for a random element. For everyday programming, though, List<T>
is usually the faster and lighter choice.
๐ PDF Download
Need a handy summary for your notes? Download this topic as a PDF!