INF210 Lec9 Data Structures
INF210 Lec9 Data Structures
INF 210
Fall 2022-2023
Lecture 9
The LinkedList
INSTRUCTOR
DR/ AYMAN SOLIMAN & DR/ OSAMA FAROUK
Ø Contents
1) LinkedList Basics
2) Linked List Visualization
3) Adding and Removing Information
4) Time Complexity Equations
5) Uses for LinkedLists
6) Review and Conclusion
7) One Big Drawback
Employee
Salary
Sector
Age
Node
Node
Node
Node
Data
Node
Data Reference/
Pointer
Node
Strings
Data Reference/
Pointer
Node
Strings
Integers
Data Reference/
Pointer
Node
Strings
Integers
Data Reference/
Pointer
Booleans
Node
Strings
Integers
Data Reference/
Pointer
Booleans
Node
Strings
Node
Node
Reference/
Data Pointer
Linked List
Linked List
Head Node
Linked List
Head Node
Reference/
Data Pointer
Linked List
Head Node
Reference/
Data Pointer
Linked List
Head Node
Reference/
Data Pointer
null
Linked List
Head Node
Reference/ Reference/
Data Pointer Data Pointer
null
Linked List
Head Node
Reference/ Reference/
Data Pointer Data Pointer
1 2
null
Linked List
Head Node
Reference/ Reference/
Data Pointer Data Pointer
1 2
null
Linked List
Head Node
Reference/ Reference/
Data Pointer Data Pointer
1 2
null
Linked List
Head Node
Reference/ Reference/
Data Pointer Data Pointer
1 2
null
Linked List
Reference/ Reference/
Data Pointer Data Pointer
1 2
null
Linked List
1 2
null
Linked List
1 2 3
null
Linked List
1 2 3
null
Linked List
1 2 3
null
Linked List
1 2 3
null
Linked List
1 2 3
null
Linked List
1 2 3
null
Linked List
1 2 3
null
Linked List
1 2 3
null
Linked List
1 2 3
null
Linked List
1 2 3
null
Stack
Queue
Stack
Queue
Stack
Queue
Stack
Queue
Stack
Add to Head
Remove from
Head
Add to the
Add to Head
Middle
Add to the
Add to Head Add to Tail
Middle
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
Head Node
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
Make that new Node’s pointer point to the current Head of the LinkedList
1 2 3
null
Make that new Node’s pointer point to the current Head of the LinkedList
1 2 3
null
Data Reference/Pointer
Make that new Node’s pointer point to the current Head of the LinkedList
1 2 3
null
Data Reference/Pointer
Make that new Node’s pointer point to the current Head of the LinkedList
1 2 3
null
Data Reference/Pointer
Make that new Node’s pointer point to the current Head of the LinkedList
1 2 3
null
Data Reference/Pointer
1 2 3
null
Data Reference/Pointer
1 2 3
null
Data Reference/Pointer
1 2 3
null
Data Reference/Pointer
1 2 3
null
Data Reference/Pointer
1 2 3
null
Data Reference/Pointer
1 2 3
null
Data Reference/Pointer
1 2 3
null
Data Reference/Pointer
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
Data Reference/Pointer
1.5
1 2 3
null
Data Reference/Pointer
1.5
1 2 3
null
Data Reference/Pointer
1.5
1 2 3
null
Data Reference/Pointer
1.5
1 2 3
null
Data Reference/Pointer
1.5
1 2 3
null
Data Reference/Pointer
1.5
1 2 3
null
Data Reference/Pointer
1.5
Make the pointer of the Node previous to the one we’re removing, to now
point to the Node after the one we’re removing
1 2 3
null
Data Reference/Pointer
1.5
Make the pointer of the Node previous to the one we’re removing, to now
point to the Node after the one we’re removing
1 2 3
null
Data Reference/Pointer
1.5
Make the pointer of the Node previous to the one we’re removing, to now
point to the Node after the one we’re removing
1 2 3
null
Data Reference/Pointer
1.5
Make the pointer of the Node previous to the one we’re removing, to now
point to the Node after the one we’re removing
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
Make the current tail point towards the new Node you want to add
1 2 3
null
Make the current tail point towards the new Node you want to add
1 2 3
Make the current tail point towards the new Node you want to add
1 2 3
Make the current tail point towards the new Node you want to add
1 2 3
Make the current tail point towards the new Node you want to add
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
null
1 2 3
null
1 2 3
null
Accessing
Accessing
O(n)
1 2 3
Accessing
null
O(n)
1 2 3
Accessing
null
O(n)
1 2 3
Accessing
null
O(n)
1 2 3
Accessing
null
O(n)
1 2 3
Accessing
null
O(n)
1 2 3
Accessing
null
O(n)
Accessing Searching
O(n)
Accessing Searching
O(n) O(n)
Data Reference/Pointer
Data Reference/Pointer
2
Accessing Searching
Data Reference/Pointer
3
O(n) O(n)
null
Data Reference/Pointer
Data Reference/Pointer
2
Accessing Searching
Data Reference/Pointer
3
O(n) O(n)
null
Data Reference/Pointer
Data Reference/Pointer
2
Accessing Searching
Data Reference/Pointer
3
O(n) O(n)
null
Data Reference/Pointer
Data Reference/Pointer
2
Accessing Searching
Data Reference/Pointer
3
O(n) O(n)
null
Data Reference/Pointer
Data Reference/Pointer
2
Accessing Searching
Data Reference/Pointer
3
O(n) O(n)
null
O(n) O(n)
O(n) O(n)
O(n) O(n)
O(n) O(n)
Array
Behind the Scenes
ArrayList
Data Reference/Pointer
1
Data Reference/Pointer
null
Data Reference/Pointer
1
Data Reference/Pointer
null
Stack
Data Reference/Pointer
Queue
1
Data Reference/Pointer
null
Stack
T i t l e
Length
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null
1 2 3
null