Week 5
Week 5
● Linear(arrays) vs nonlinear (pointer) structures – Run time and space requirements, when to use
what?
● Introduction to linked list, Examples: Image viewer, music player list etc. (to be used to explain concept
of list), applications.
Arrays
An array is a sequential list of data. Being sequential means that each element is stored right
after the previous one in memory.
Advantages:
Disadvantages:
• Fixed size
• one block allocation
• complex position based insertion
Pointer
In Python, you don't manipulate pointers directly, unlike in some other languages, such as C or
Pascal.
We would normally say that x is a variable which is holding value 2337 but this is not strictly
true, however.
Pointer structures are lists of items that can be spread out in memory. This is because each
item contains one or more links to other items in the structure.
What type of links these are dependent on the type of structure we have. If we are dealing with
linked lists, then we will have links to the next items in the structure. In the case of a tree, we
have parent-child links as well as sibling links.
Benefits:
• They don't require sequential storage space.
• They can start small and grow arbitrarily as you add more nodes to the structure.
1. Image viewer – Previous and next images are linked, hence can be accessed by next and
previous button.
2. Previous and next page in web browser – We can access previous and next url searched
in web browser by pressing back and next button since, they are linked as linked list.
3. Music Player – Songs in music player are linked to previous and next song. you can play
songs either from starting or ending of the list.