Linked List
Def: A linked list is a dynamic data structure, what I mean by that is you can add or remove data in a linked list. They store data in a sequential manner but not in a contiguous way. Array's if you have ever heard of them store data in a contigous way
This is how arrays are stored in memory
However unlike arrays, linked list are stored differently. see the image below:
Why Use a linked list?
- Because of the way they are stored in memory, it's easier to insert or delete a node.
- In linked list overflow is rarely an issue because data is stored.
- Because of how memory is allocated, the size of a linked list is not pre-defined therefore you can increase or reduce the size of the data as you wish.
Where is the Linked list used in real-life examples?
- Say you are playing a playlist with your favorite musician, you can toggle between the next song or the previous as you like. Behind the scenes, it's actually implementing a linked list, in that play next button is a pointer to the next song (node) and the back button refers to the previous song (previous node).