DEV Community

Play Button Pause Button
Vaidehi Joshi
Vaidehi Joshi

Posted on

Linked Lists — BaseCS Video Series

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.

Top comments (30)

andy profile image
Andy Zhao (he/him) • Edited

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

isaacdlyman profile image
Isaac Lyman

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?

stefannibrasil profile image
Stefanni Brasil • Edited

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.

juanita profile image
Juanita Soranno

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 :)

salmaeng profile image
Salma Elshahwy

so helpful, Thank you

katylava profile image
katy lavallee

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?

ben profile image
Ben Halpern

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.

katylava profile image
katy lavallee


ben profile image
Ben Halpern

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 🙃

coolnerdcool profile image

So glad that I've found this new series.


chenge profile image
chenge • Edited

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 =, :next)

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

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

3.times { |i| list = linked_list(i, list) } # O(1)
igormp profile image
Igor Moura

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.

kspeakman profile image
Kasey Speakman

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.

enrikacreates profile image

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!

abooayoob profile image
Mohammad Ali Khan

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?

maestromac profile image
Mac Siri

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

androminor profile image
Varun Singh

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

hullsean profile image
Sean Hull

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!