Linked List

Today I learned about Linked List.
It's a data structure that makes it easier to add and remove data in a specific order...

The simplest way I think about linked list is like a train...
There is a always a head and a tail and each car of the train is connected in two points, front and back.



The way a linked list can be used in Js is by creating a list obj, and "node" objs that stores the data and at the same time points to a node it the front of it and a node in the back of it.

The cool thing about link list is that the "list" obj itself is a really small data obj in size.
That only contains the first node and the last node in the chain.

```javaScript

function LinkedList() {
  this.head = null;
  this.tail = null;
}
function Node(value, next, prev) {
  this.value = value;
  this.next = next;
  this.prev = prev;
}

```

Another analogy is that a link list is a chain, like an array data type.
You can easily add to the front or the back of the chain/list but you can't just add one in the middle somewhere.

Linked list has a fast runtime.

when add/remove elements it has a  BigO constant time :)
when searching it has a  BigO linear time :(

In terms of memory management you don't need to store linked list together, in lower lvl language
like in C++ etc, which is nice.

Comments

Popular posts from this blog

CSS Review

Binary Search Tree

Hash Table