Stage 2 · Lesson 2 of 6
Singly and doubly linked lists
A stores each item in its own node, and each node points to the next one, like a trail of clues where each tells you where the next is. In a singly linked list the nodes only point forward. In a each node also points back to the previous one.
Inserting or removing a node you already hold is O(1), because nothing has to shift. But reaching the i-th item means walking from the start (the head), which is O(n). You will rarely pick one over a , but they matter for two reasons.
They are the building block of other structures, such as and the chains inside hash maps. And pointer problems, like reversing, merging or finding the middle, are the best practice there is for careful code. A , a fake first node before the real ones, removes most edge cases.
A question to check yourself, an AI practice session and 3 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Data Structures & Algorithms for Coding Interviews
Design Gurus · Beginner · Subscription
Each structure from first principles, with solutions in Python, Java, C++ and JavaScript
- CourseFreeMIT 6.006 Introduction to Algorithms
MIT OpenCourseWare · Intermediate
Free: lectures 2 and 4 cover dynamic arrays, linked lists, sets and hashing
Practise
Keep handy
Also worth your time
How to pick a structure from the operations a problem needs