Linked List vs Array

In this lesson, we'll discuss the motivation for a better data structure to represent linear data than arrays.

Why do we need a list

A major problem with arrays is that the size is fixed. For example, adjacency list representation of a graph is not possible with 2-D arrays. It’s fine if you don’t know what adjacency list is just yet, we’ll discuss that in later chapters. But this is just an example of why we need arrays that are dynamic in size.

So, we create a linked list where each node, along with the value, stores a pointer to the next node.

Get hands-on with 1200+ tech skills courses.