Play Button Pause Button

Linked Lists — BaseCS Video Series

vaidehijoshi profile image Vaidehi Joshi ・1 min read

You might have heard about linked lists, or you might think that you're supposed to know about them. Maybe you do know a little bit about them, but don't know why you should care or why they matter. Either way, I want to tell you about why they're so cool.

For much more on linked lists, check out the articles that accompany the video series:

Leave questions and comments below!

SparkPost Logo

This video series is sponsored by SparkPost. There's never been a better way for developers to send email.

Posted on by:

vaidehijoshi profile

Vaidehi Joshi


Writing words, writing code. Sometimes doing both at once. Señiorita engineer at Forem.


Editor guide

As someone without a CS degree myself, and a less-than-stellar grip of some of these topics, this series excites me a lot. And I'm not just saying that because I helped make it 🙃


Super excited for this release! I'm both a visual and auditory learner, so this is perfect! 👌


This is great! One question: does the head node of a linked list contain data also, or just a pointer? I ask because you refer a couple of times to the second box in the linked list as "the first node," which confused me because visually it looks like the second node. And in the circular linked list, the tail node doesn't point back to the head. So this makes me think that the head node is "empty". Is that right?


Hi, Isaac, that's really good question. Hope I can help you. But yes, the nodes usually contain data. But it depends on what you want to do, you may need to use the 'head' just use it as a pointer, so it's not required to have data on your head node.


I. can't. even. explain how excited the prospect of this series makes me. I actually understand Big O now. Thank you! I'm sharing this with my team as we speak. Keep it up :)


so helpful, Thank you


Is there going to be a single url where I can discover the rest from? I thought it might be this page, but I guess this is just about linked lists?


This is just the linked list page, but @vaidehijoshi 's profile will have the new ones. If you follow her you'll get new posts in your notifications.


So glad that I've found this new series.



Excellent explanation as always. I use linked lists all the time since most FP lists are implemented as linked lists.

A word of caution though, you have to be careful of using linked lists in hot code. Even though they have O(n) characteristics, they can be significantly slower than arrays. Because of the way CPUs work, when it reads something from memory into CPU cache for processing, it reads surrounding data as well (cache line). Since array elements are stored next to each other, the CPU may be able to process multiple array elements with a single memory fetch. Whereas with linked lists, there is a high chance that every element will require a fetch from memory, greatly increasing processing time when iterating the list.

This is why in many languages, variable-size lists are actually backed with arrays. For instance in C#, the generic list List<T> allocates an array, and keeps track of how much free space is on the end. When you add an element and there is no free space, it allocates a new array of twice the size and copies the elements to it. The copy is expensive but, amortized over the life the object, is still much faster than using a linked list for many kinds of workflows.

I mention this because I have actually run into this issue when using an LRU cache in hot code. I tried both a linked-list implementation and an array-backed circular buffer, and there was a world of difference in the performance, as in the linked list became the bottleneck instead of the disk IO.


Amazing video! And those handwritten drawing and explanations are just gorgeous to look at.

The only thing I've missed was the explanation for sorted linked lists, this may be a nice topic for another video. Another neat follow up would be explaining stacks and queues, since their implementations are actually very similar to the one of a linked list.


Your video is great, but where is code sample?

Here is a simple one, only add node.

# create a struct with :value and :next
Cell = Struct.new(:value, :next)

# create a head of our list
list = Cell.new("head. hi", nil)

# method which create one more cell and return the struct
def linked_list(value, cell)
  return Cell.new(value, cell)

3.times { |i| list = linked_list(i, list) } # O(1)

Hey Vaidehi I followed you after watching the fantastic speaking up by you in treehous live streaming festival. You have given me a lost reason, and inspiration to come back to CS: ALGORITHM . Now I really want to know how did you upload videos on all your posts here using. What video platform did you use ? Please share the insight period


Awesome stuff! Looking forward to the rest of the series 🙌🏼


Awe this is sooo refreshing. So glad I checked this out. I am excited about what else you guys are teaching!! Hopefully to learn a lot here!


This is really cool! I have been listening to the base.cs podcast, and want to watch the videoseries :) However, I am finding this a little bit hard to navigate: Is this the first video in the series? Is there a linked list for this videoseries somewhere? Does it follow the same sequence as the medium posts or base.cs podcasts?


This is a really great explanation Vaidehi. Very clear & easy to follow. I wish my teacher was as good as you, when I learned these introductory concepts.

Well done!


Hi ! It look like something went wrong cause the player says "error loading media : file could not be played"


Amazing video! The content is explained and presented very well. Looking forward to more of these!


Really enjoyed this video and you helped to clear up some gaps in my knowledge when it comes to linked lists! Can't wait to watch your other videos!


Can't wait for the next topic in video!!


Thank you for your effort in putting this topic on video. Hope to see more.


I'm a visual learner so I loved the diagrams and different colours of markers, it made it easier to visualise the linked lists in my head, looking forward to watching the next series of videos 🕺🏿 🕺🏿


Is anyone else experiencing issues playing the video? I am on Firefox (tried a few different networks).

Edit: Oh, videos do not work in Firefox!


Actually. Edit edit: Firefox seems to buffer the entire video before playback starts.


Well explained. Looking forward to more such posts from you Vaidehi Joshi.