Save
MIDTERM_2ND SEM.1
Data Structure & Algorithm Analysis
LINKED LIST
Save
Share
Learn
Content
Leaderboard
Share
Learn
Created by
rein
Visit profile
Cards (18)
Linked List
A linear data structure where
elements
(
nodes
) are linked using
pointers
.
Unlike
arrays
,
linked lists
allow
dynamic memory allocation
, making them more efficient for inserting and deleting elements.
Why use
linked list
?
Dynamic Size
: can grow or shrink at runtime
Why use
linked list
?
Efficient
Insertions/Deletions
: no need to shift elements like in arrays
Why use
linked list
?
Memory Utilizations
: uses only the memory
needed
Node
Fundamental building block of a
linked list
. Each node consist of:
data
, and
pointer
Each
node
consist of:
Data
- stores the value.
Pointer
- stores the address of the next node
insertAtBeginning(Node*& head, int value)
creates a new
node
with the given value and makes it the new
head
of the list
insertAtEndg(Node*& head, int value)
creates a new
node
with the given
value
and
adds
it to the end of the
list
deleteNodeg(Node*& head, int key)
searches for a node with the given value and removes it from the list
displayList(Node* head)
traverses
the
linked list
and prints each node’s value
LINKED LIST VS ARRAY
A)
sequentially
B)
randomly
C)
grow and shrink
D)
specified
E)
expand
F)
fixed
G)
memory
H)
ineffective
I)
different
J)
single
K)
runtime
L)
compilation
12
TYPES OF LINKED LISTS
Singly Linked List
Doubly Linked List
Circular Linked List
Singly Linked List
each
node
points to the next node.
Doubly Linked List
each
node
has pointers to both next and previous node.
Circular Linked List
last
node
links back to the first node.
ADVANTAGES
Dynamic Memory Allocation
- unlike arrays,
linked lists
can dynamically grow and shrink is needed.
Efficients
Insertions
and
Deletions
- no need to shift elements like in an array.
Better
Memory Utilizations
- only uses memory as required without wasting space.
Flexible Data Structure
- can easily implement stacks, queues, and graphs.
Fast Insertions
and Deletions in Middle - unlike arrays, inserting or deleting an element does not require shifting.
DISADVANTAGES
Increased
Memory Usage
- each node requires extra memory for a
pointer
Slower
Access Time
- elements must be accessed sequentially, unlike
arrays
with direct indexing.
Complex
Implementation
- managing
pointers
can be tricky and may lead to
memory leaks
.
Extra
Overhead
- maintaining pointers consume additional
processing power
.
No
Cache Friendly
- linked lists have poor
cache locality
, making traversal slower than arrays.