Slide02b - Data Structures and Algorithms
Slide02b - Data Structures and Algorithms
TCC236/05
Table of Contents
Recall
List
Linked lists
Single linear linked list
Comprises only 1 link
The link points to the next data element in the list.
The last element points to the null.
The first node is usually called the Head node.
ADT
Operations / Algorithms:
Create
Insert
Delete
Traverse
Table of Contents
What’s new?
Table of Contents
Objectives
Introduction
Example double linked list:
Introduction
Example double linked list:
(I) Operations
(II) Operations
1 Traverse the list until data 20 is found. Assign that node as prevnode.
2 Create a new node with data 25 (which is to be inserted)
(II) Operations
(II) Operations
(II) Operations
(II) Operations
Insertion of a node in a double linked list - START
(III) Operations
(III) Operations
Deletion of a node from a double linked list - MID
(IV) Operations
Table of Contents
Objectives
Introduction
(I) Operations
(II) Operations
Table of Contents
Summary
Pros:
Simple in implementation
Requires relatively lesser memory for storage (1 link compared to 2 in
doubly)
Cons:
Cannot be iterated in reverse order.
Needs to maintain a pointer to the head node. Otherwise the list will
be lost in memory.
When deleting or inserting at previous node, one needs to traverse the
list from the head to the node - requires O(N) time.
When to use?
Have limited memory to spare.
Requires heavy insert/delete operations, rather than search/read.
Pros:
Can iterate in forward or backward directions.
In the case of needing to delete previous node, there is no need to
traverse from head node as the node to be deleted can be found from
previous pointer - requires O(1) time.
Cons:
Relatively more complex to implement.
Requires more memory for storing additional pointers per node
(previous and next).
Insertions and deletions are relatively more time consuming, i.e.
assigning/reassigning pointers for neighbour nodes.
When to use?
Have lots of memory to spare.
Requires heavy search/read, rather than insert/delete operations.