Monday, October 12, 2015

Data Structures - Arrays and Linked Lists

An array is a random access data structure, while a linked list is a sequential access data structure. So, what's the difference between random and sequential?

Well, random means you can access something directly, and sequential means in order to access something, you have to go one by one. See this:

Arrays:

Linked lists:

or

The differences between the two different linked lists, we'll talk about later. But the difference between arrays and linked lists, we will talk about :D

Okay, the difference: Arrays, can be access directly, like some array A and some index -> A[0].
In the above example of an array, A[0] would = 10, A[1] = 6,  A[2] = 7, and so on. The way to access these indices is very direct, like opening a book to a specific page, assuming that there's bookmarks to every page...

Linked lists on the other hand, are linked someway, the first one in only one direction. For the first linked list, it is analogous to......to.......... walking into a huge cave and every step you get a boulder behind you, you can't go back, sadly.

The second one is linked bidirectionally, which means you can go back and forth between elements, like a string of rooms each with a door. 

Yup, that's all.

I'll add more to this if I find that I have left anything out, and I hope this explains to you arrays and linked lists!

Here's to part 2: Implementation



0 comments:

Post a Comment