Friday, March 20, 2015

Impressions of Week8.

    In this post, i will summarize the “Linked list” because i feel I get lost in this week.


LLNode


Linked list is data structure which has node(data) and link connecting each nodes .
Each node also contains “reference address”(This is just for my understanding. Not formal vocabulary describing LLNode.) which tells the next node.

LLNode is generally considered as “Recursive data structure”.
The node can have next data (node.next) or it can be simply a single node contains single value in which node.next is None.

According to this code, self.cargo is the value of the node and self.next is reference address. 

This is how you make node1, node2, and node3 with value 1 , 2 and 3 respectively.
If i visualize this sturcture, I can come up with something like this. 


As you can observe, the nodes are not connected to each other, they are just three single nodes.
If I want to make them to be connected, I can do this by assigning node2 as node1.next and node3 as node2.next. 


Then I will come up with this kind of data structure! 

In the last blog post, I said ‘I don’t understand why people made this kind of data structure since we already have “List” object.'
However, now I totally get why this data structure has been developed and realized that this LLNode is totally different concept compare to list object.
We can take some advantages from LLNode :
  • You never run out of room and have to copy to a new location.
  • Adding & deleting in the middle of the list is simpler.
As always, however, there are some disadvantage if there are advantages!!!
    - NO random access!
    - Finding list element N is slower when N is large.


No comments:

Post a Comment