linked lists vs arrays (lists)
three operations performed on linked lists
traversed to obtain info, node can be added to list, node can be removed from list
array disadvantages
adding or removing from anywhere but the end requires shifting elements over
linked list advantages
best when many removals and additions are needed. both are O(1)
special pointer
called node to indicate absence of a node's successor
singly linked list
each node, except the last one contains a single pointer to the next element
doubly linked list
every node, except the first and last, contain pointers to both its successor and predecessor
nodes of linked lists can only be accessed
in a sequential manner, you have to traverse through the entire chain of pointers until the particular node is reached. the time to access an element depends on where the element is located in the list
linked list
linear data structure with sequence of zero or more elements called nodes
in a linked list, each element sits
separately in its own block of memory. we call this small separate block of memory a node
linked lists contains two kinds of info:
some data and one or more likes called pointers to other nodes of the linked list
array advantages
sorted, and allows for random read access so you can grab any element in constant time.
nodes in a linked list can be allocated
on an as needed basis. when no longer needed the nodes can be returned to the memory manager
linked list disadvantages
only sequential access of elements O(N) You can walk forwards or backwards but finding a position in list takes time proportional to the size of list (no random access capabilities)
