Hi there!
This week, we have learned more about linked lists. I haven't explained in depth what LinkedLists were in my previous blogs, but that's because we haven't learned about it in depth until now.
What is a LinkedList? Well it is as it sounds. Put simply, it is a series of linked nodes. I have went over nodes already, but I will explain what they are for any newcomers. A node is simply a part of a LinkedList. That is, a node has some sort of data, or cargo, and possibly a single link to another node . The confusing part of a LinkedList is understanding how they are designed.
Note: The alternate term to 'link' is 'rest', but I personally like 'link' better.
The first time that I have attempted to recreate a LinkedList was quite troublesome. This is because I did not understand how to store more than one node containing some data without using Python's primitive list data type. I have only encountered this problem because I did not see that the "links" of the LinkedList are just other LinkedList nodes.
A LinkedList node will have some cargo or value containing some data, and children as its attributes. To continue the "chain" of data, the child will simply be the next LinkedList node. If there's more data, then the child will have it's own child. Then the child's child will have another child with additional data, and so on. Eventually, the last child of a node will point to None if there's no more data (that's so sad...).
The functions of a LinkedList node would involve the procedure of adding more 'data' or LinkedList nodes, usually called "prepend" (adds to the beginning of the chain, which is counter-intuitive), a method to remove a node at the end of a LinkedList, called "decapitate" (sounds quite intrusive), inserting nodes, deleting nodes and reversing nodes (those method names should be obvious and self-explanatory).
The last thing I want to mention about is binary search, which is a searching algorithm. Basically, this type of search starts at the middle node of the LinkedList, creates an upper-set and a lower-set of nodes (where upper-set goes towards the end, lower-set goes towards the beginning), and each node is checked above and below until some data is found. In your mind, imagine a ball that bounces higher and higher each time it drops. Then imagine a trajectory of the ball and imagine a horizontal lines showing the symmetry of each drop and bounce. That is essentially what binary search does. It starts in the middle of the list and it works its way out both ways.
Anyways...
I can't believe that the course is nearly over! This course is still quite easy to me, and I hope it stays that way.
I really need to prepare for those exams...
That's all from me today!
Bye for now!
I appreciate your comparison of binary search to the bouncing of a ball. Real life comparisons often help to put these otherwise theoretical concepts into perspective.
ReplyDelete