100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

Operations on Linked Lists: Insertion, Deletion, and Traversal

Rating
-
Sold
-
Pages
7
Uploaded on
28-01-2025
Written in
2024/2025

This document covers the essential operations on linked lists, including insertion, deletion, and traversal techniques for singly and doubly linked lists, explained with practical examples and code snippets.










Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
January 28, 2025
Number of pages
7
Written in
2024/2025
Type
Other
Person
Unknown

Content preview

Operations on Linked Lists
Linked lists support several essential operations that allow you to manipulate the
data in the list. These operations vary depending on the type of linked list (singly,
doubly, or circular). Below are some of the most common operations on linked
lists.



1. Basic Operations
1.1 Traversal

Traversal refers to the process of visiting each node in the linked list. This
operation is typically used to display all elements of the list or search for a
particular element.

 Singly Linked List: Start from the head and follow the next pointers until
reaching null.
 Doubly Linked List: Traverse from the head to the last node and back using
both next and prev pointers.
 Circular Linked List: Traverse starting from the head and continue until
reaching the head again.

Example (Python - Singly Linked List):

def traverse(self):
current = self.head
while current:
print(current.data, end=" -> ")
current = current.next
print("None")


1.2 Insertion

Insertion involves adding a new node at a specific position in the linked list.
Common insertion operations include:

,  At the beginning: Insert the node at the head of the list.
 At the end: Insert the node at the last position.
 At a specific position: Insert the node at a given index.

Example (Python - Insert at the Beginning for Singly Linked List):

def insert_at_beginning(self, data):
new_node = Node(data)
new_node.next = self.head
self.head = new_node

Insert at the End for Singly Linked List:

def insert_at_end(self, data):
new_node = Node(data)
if not self.head:
self.head = new_node
return
current = self.head
while current.next:
current = current.next
current.next = new_node


1.3 Deletion

Deletion involves removing a node from the linked list. The most common
deletions are:

 Delete from the beginning: Remove the head node.
 Delete from the end: Remove the last node.
 Delete by value: Remove a specific node containing a given value.
 Delete by position: Remove the node at a specific index.

Example (Python - Delete from the Beginning for Singly Linked List):

def delete_from_beginning(self):
if self.head:
self.head = self.head.next
$6.09
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
rileyclover179

Also available in package deal

Thumbnail
Package deal
Complete Linked Lists Exam Study Pack and Q&A (10 Documents)
-
10 2025
$ 63.00 More info

Get to know the seller

Seller avatar
rileyclover179 US
View profile
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
10 months
Number of followers
0
Documents
252
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions