Posts

Showing posts with the label linked list

Linked List

Image
Shall we start with the typical definition then? According to Wikipedia : In  computer science , a  linked list  is a linear collection of data elements, whose order is not given by their physical placement in memory. Instead, each element  points  to the next.   If this isn't clear (and I know it's not), lemme tell you how it's different from arrays and then the concept shall make itself more clear as we proceed from there. We can imagine an array as a long-ass bench in a class with a certain seating capacity (say 9), and there are 7 people sitting in it currently. When we initialize an array, we have to set it to a particular size. That size might be 7, 9, 10, or 100, or 1000 or whatever. But if we don't know exactly how many people are going to sit, how do we decide the size? If we take a huge-ass bench (big size array), it'll take a lot of space in the class (in computer memory), but if enough students don't show up, all that extra space would be wasted.  Co