# Ds Lab Manual
# Ds Lab Manual
Basic programs of C
A 4. WAP to find the largest among the given three numbers by user.
B 6. WAP to convert seconds into hours, minutes & seconds and print in HH:MM:SS
[e.g. 10000 seconds mean 2:46:40 (2 Hours, 46 Minutes, 40 Seconds)].
C 7. WAP to convert number of days into year, week & days [e.g. 375 days mean 1
year, 1 week and 3 days].
Unit: I – Array
A 19. Write a program to find position of the smallest number & the largest number
from given n numbers.
B 20. Write a program to find whether the array contains a duplicate number or not.
Page 1 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
B 21. Read n numbers in an array then read two different numbers, replace 1 st
number with 2nd number in an array and print its index and final array.
B 27. Write a program to delete a number from an array that is already sorted in an
ascending order.
5 A 31. Read two 2x2 matrices and perform addition of matrices into third matrix and
print it
A 32. Read two matrices, first 3x2 and second 2x3, perform multiplication operation
and store result in third matrix and print it.
Page 2 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
Unit: I – Stack
6 A 34. Write a menu driven program to implement following operations on the Stack
using an Array
• PUSH, POP, DISPLAY
• PEEP, CHANGE
A 35. How stack can be used to recognize strings aca, bcb, abcba, abbcbba? Write a
program to solve the above problem.
B 36. Write a program to determine if an input character string is of the form a ibi
where i >= 1 i.e., Number of ‘a’ should be equal to number of ‘b’.
Input Format:
The first line of the input contains a single integer T denoting the number of
test cases. The description of T test cases follows. The first and only line of
each test case contains a single string
Output Format:
For each test case, print a single line containing the answer.
Sample Example:
Input: Output:
1
4 0
() 1
([)] 0
([{}()])[{}]
[{{}]
Page 3 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
Note :
• The input will be generated such that the operation is always possible.
• It can be shown that the resulting string will always be unique.
Sample Example-1:
Input: s = "leet**cod*e".
Output: "lecoe"
Sample Example-2:
Input: s = "erase*****"
Output: ""
Sample Example-1:
Input: Intervals = {{1,3},{2,4},{6,8},{9,10}}
Output: {{1, 4}, {6, 8}, {9, 10}}
Explanation: Given intervals: [1,3],[2,4],[6,8],[9,10], we have only two overlapping
intervals here,[1,3] and [2,4]. Therefore we will merge these two and return [1,4],[6,8],
[9,10]
Sample Example-2:
Input: Intervals = {{6,8},{1,9},{2,4},{4,7}}
Output: {{1, 9}}
Page 4 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
Input Format:
• First line will contain T, number of test cases. Then T test cases follow.
• The first line of each test case contains N, the length of the string.
• The second line contains S, the string itself.
Output Format:
For each test case, output in a single line the final string after traversing S from
left to right and performing the necessary reversals.
Sample Example:
Input: Output:
2 hgfeabcdij
10 gacbade
abcdefghij
7
bcadage
7 A 41. Write a program to convert infix notation to postfix notation using stack.
B 42. Write a program to convert infix notation to prefix notation using stack.
Page 5 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
C 45. You have an array A of integers of size N, an array B (initially empty) and a stack
S (initially empty). You are allowed to do the following operations:
• Take the first element of array A and push it into S and remove it from A.
• Take the top element from stack S, append it to the end of array B and
remove it from S.
You have to tell if it possible to move all the elements of array A to array B using
the above operations such that finally the array B is sorted in ascending order.
Input Format :
• First line will contain T, number of testcases. Then the testcases follow.
• First line of each testcase contains a single integer N.
• Second line of each testcase contains N distinct integers : A1,A2...AN.
Output Format :
For each testcase, if it possible to move all the elements of array A to array B
using the above operations such that finally, the array B is sorted in ascending
order, print "YES" (without quotes), else print "NO" (without quotes).
Sample Example:
Input: Output:
2 YES
4 NO
1243
4
1342
Unit: II – Queue
8 A 46. Write a menu driven program to implement following operations on the Queue
using an Array
• ENQUEUE
• DEQUEUE
• DISPLAY
9 A 49. WAP to allocate and de-allocate memory for int, char and float variable at
runtime.
A 50. WAP to get and print the array elements using Pointer.
A 51. WAP to calculate the sum of n numbers using Pointer.
A 52. WAP to find the largest element in the array using Pointer.
B 53. WAP to sort the array elements using Pointer.
B 54. WAP to check whether the string is Palindrome or not using Pointer.
C 55. WAP to define a C structure named Student (roll_no, name, branch and
batch_no) and also to access the structure members using Pointer.
10 A 56. Write a program to implement a node structure for singly linked list. Read the
data in a node, print the node.
A 57. Write a menu driven program to implement following operations on the singly
linked list.
• Insert a node at the front of the linked list.
• Display all nodes.
• Delete a first node of the linked list.
• Insert a node at the end of the linked list.
• Delete a last node of the linked list.
• Delete a node from specified position.
• count the number of nodes
B 58. WAP to check whether 2 singly linked lists are same or not.
C 59. Write a program to remove the duplicates nodes from given sorted Linked List.
• Input: 1 → 1 → 6 → 13 → 13 → 13 → 27 → 27
• Output: 1 → 6 → 13 → 27
Page 7 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
C 65. WAP to swap Kth node from beginning with Kth node from end in a singly linked
list.
B 67. WAP to perform given operation in the linked list. There exist a Linked List. Add
a node that contains the GCD of that two nodes between every pair adjacent
node of Linked List.
Input 18 6 10 3
Output 18 6 6 2 10 1 3
C 68. Write a program to swap two consecutive nodes in the linked list. Don’t change
the values of nodes, implement by changing the link of the nodes.
• Input: 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8
• Output: 2 → 1 → 4 → 3 → 6 → 5 → 8 → 7
14 A 69. Write a menu driven program to implement following operations on the circular
linked list.
• Insert a node at the front of the linked list.
• Delete a node from specified position.
• Insert a node at the end of the linked list.
• Display all nodes.
15 A 72. Write a menu driven program to implement following operations on the doubly
linked list.
• Insert a node at the front of the linked list.
• Delete a node from specified position.
• Insert a node at the end of the linked list. (Home Work)
• Display all nodes. (Home Work)
Page 8 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
C 74. Write a program to simulate music player application using suitable data
structure. There is no estimation about number of music files to be managed by
the music player. Your program should support all the basic music player
operations to play and manage the playlist.
16 A 75. Write a menu driven program to implement Binary Search Tree (BST) & perform
following operations:
• Insert a node
• Delete a node
• Search a node
• Preorder Traversal
• Postorder Traversal
• Inorder Traversal
B 76. Write a program to check whether the given two trees are same or not.
Input :
3 3
2 4 2 4
1 1
Input :
3 3
2 4 2 4
1 1
Page 9 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
17 A 77. Write a program to check whether the given tree is symmetric or not.
Input: Input:
8 8
5 5 5 7
3 6 6 3 3 6 6 3
Sample Example-1:
Sample Example-2:
18 A 79. Write a program to construct a binary tree from given Postorder and Preorder
traversal sequence.
B 80. WAP to find the smallest and largest elements in the Binary Search Tree.
Page 10 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
C 81. Write a program to implement phone book dictionary using Binary Search Tree
which provides following operations:
• Add new entry in phone book,
• Remove entry from phone book,
• Search phone number
• List all entries in ascending order of name and
• List all entries in descending order of name
19 A 82. Write a program to create a graph & implement the adjacency list
representation of the graph
• Apply DFS and BFS on the given graph.
C 84. You are given an undirected graph with N nodes (numbered 1 through N).
For each valid i, the i-th node has a weight Wi. Also, for each pair of nodes i and
j, there is an edge connecting nodes if j – i ≠ Wj - Wi.
Input Format:
• The first line of the input contains a single integer T denoting the number of
test cases. The description of T test cases follows.
• The first line of each test case contains a single integer N.
• The line contains N space-separated integers W1, W2, ..., WN.
Output Format :
For each test case, print a single line containing one integer --- the number of
components in the graph.
Sample Example:
Input: Output:
2 2
2 1
12
2
21
Page 11 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
Unit: IV – Hashing
A 88. Write a program to implement a Binary Search using Array. (Iterative &
recursive)
Page 12 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
B 98. Given an array nums with n objects colored red, white, or blue, sort them in-
place so that objects of the same color are adjacent, with the colors in the
order red, white, and blue. We will use the integers 0, 1, and 2 to represent
the color red, white, and blue, respectively.
Sample Example-1:
Input: nums = [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]
Sample Example-2:
Input: nums = [2,0,1]
Output: [0,1,2]
Page 13 of 14
Department of Computer Science & Engineering
Lab Manual | 2301CS301 – Data Structure
B. Tech. Semester – III | Academic Year 2025-26
Example:
Input:
arr = [1, 2, 1, 0, 1, 1, 0]
K=4
Output:
5
Explanation:
Subarrays with sum ≤ 4:
• [1, 2, 1] → sum = 4 → length = 3
• [2, 1, 0, 1] → sum = 4 → length = 4
• [1, 2, 1, 0, 1] → sum = 5 → too big
• [1, 0, 1, 1, 0] → sum = 3 → length = 5 (maximum)
Page 14 of 14