AS/A Computer Science: Fundamentals of data structures

Linked lists

A linked list is a dynamic data structure. Each item in a linked list consists of data and a pointer to the next item in the list. It uses a heap which is a collection of memory locations available to the list. When data is added to the list, a memory location is selected from the heap and the pointer of the previous item updated. The final value will always have a null pointer.



All lists in Python are implemented as linked lists. This is a form of functional abstraction i.e. the programmer does not need to know how the list structure is implemented just what each of the list methods available does.

Lets say we wanted to add a new name "Dan" to our list in position 1. In Python we would say names.insert(1,"Dan"). Rather than having to rearrange all the data items in the list, we simply pull another address from the heap and adjust the pointers. When an element is deleted, the pointers are once again adjusted and the memory address returned to the heap.



Knowledge check

Questions about this topic will be included in the stacks knowledge check

© All materials created by and copyright S.Goff