In class, in order for us to better understand this term, the professor gave us some examples which I find it really useful. First, the professor asked a list of volunteers to remember their seat location and stand as a list. Then a new volunteer add into the list, which makes the whole list of volunteers move. This is an example to show the disadvantages of list. Later, the professor asked the volunteers to ask the sitting location of the volunteer that is after them. Then after the volunteers went back to their original seats, the professor can recall the list of volunteers according to the information that the volunteer record about the person after them. Also, it will be easy to add a people in the middle of the Linked List as we just need to change two people's location. This example helps us to understand the pros and cons of list and the concept of Linked List and Linked List Node.
Monday, 15 February 2016
CSC 148 Python Week 5 Slog: List and Linked List, which one is better?
This week, we got introduced to Linked List and the professor gave us some real world examples about the difference between List and Linked List. Basically, Regular Python Lists have some advantages like can efficiently be accessed. But they allocate large blocks of contiguous memory, which becomes increasing difficult as memory is in use. For Linked Lists, they have the Linked List Nodes which reserve just enough memory for the object value they want to refer to, and the linked lists can efficiently grow and shrink as needed. Here, this image is a good example of Linked List. From the following graph, we can see that each linked list contains a node which indicate the next number it should refer to:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment