0% found this document useful (0 votes)
2 views

DSA_1_ProblemSet_Linked_list

This document outlines a problem set for a lab on Linked Lists in a Data Structures and Algorithms course. It includes ten problems, such as creating and displaying a singly linked list, inserting and deleting nodes, searching for elements, reversing the list, and merging two sorted lists. Each problem provides example inputs and expected outputs to guide the implementation.

Uploaded by

shuvra098
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

DSA_1_ProblemSet_Linked_list

This document outlines a problem set for a lab on Linked Lists in a Data Structures and Algorithms course. It includes ten problems, such as creating and displaying a singly linked list, inserting and deleting nodes, searching for elements, reversing the list, and merging two sorted lists. Each problem provides example inputs and expected outputs to guide the implementation.

Uploaded by

shuvra098
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSE 2216 : Data Structures and Algorithm 1 Lab

Problem Set for Linked List

1. Create and Display a Singly Linked List


Problem:
Write a program to create a singly linked list and display its elements. Allow the user to input
the values for the nodes.
Example Input:
Values = [10, 20, 30, 40]
Example Output:
Linked List: 10 → 20 → 30 → 40 → NULL

2. Insert at the Beginning of the List


Problem:
Implement a function to insert a new node at the beginning of a singly linked list.
Example Input:
List = [20, 30, 40], Value = 10
Example Output:
Linked List: 10 → 20 → 30 → 40 → NULL

3. Insert at the End of the List


Problem:
Write a function to insert a new node at the end of the singly linked list.
Example Input:
List = [10, 20, 30], Value = 40
Example Output:
Linked List: 10 → 20 → 30 → 40 → NULL

4. Delete a Node by Value


Problem:
Write a function to delete the first node with a specific value in a singly linked list.
Example Input:
List = [10, 20, 30, 40], Value = 30
Example Output:

1
Linked List: 10 → 20 → 40 → NULL

5. Search for an Element in the List


Problem:
Implement a function to search for a specific value in the singly linked list and return its posi-
tion. If not found, return -1.
Example Input:
List = [10, 20, 30, 40], Value = 30
Example Output:
Position: 3

6. Reverse a Singly Linked List


Problem:
Write a function to reverse the singly linked list in place.
Example Input:
List = [10, 20, 30, 40]
Example Output:
Reversed List: 40 → 30 → 20 → 10 → NULL

7. Find the Middle Node of the List


Problem:
Implement a function to find the middle node of a singly linked list. If the list has an even
number of nodes, return the second middle node.
Example Input:
List = [10, 20, 30, 40, 50]
Example Output:
Middle Node: 30

8. Detect and Remove a Cycle


Problem:
Detect if a cycle exists in a singly linked list and remove it.
Example Input:
List with Cycle: [10 → 20 → 30 → 40 → 20 (back to 20)]
Example Output:
Cycle Removed: 10 → 20 → 30 → 40 → NULL

2
9. Merge Two Sorted Singly Linked Lists
Problem:
Given two singly linked lists sorted in ascending order, merge them into one sorted linked list.
Example Input:
List1 = [10, 30, 50], List2 = [20, 40, 60]
Example Output:
Merged List: 10 → 20 → 30 → 40 → 50 → 60 → NULL

10. Remove Duplicates from a Sorted Singly Linked List


Problem:
Write a function to remove all duplicate elements from a sorted singly linked list.
Example Input:
List = [10, 10, 20, 30, 30, 40]
Example Output:
Modified List: 10 → 20 → 30 → 40 → NULL

You might also like