DS_Lab_manual R23
DS_Lab_manual R23
(Autonomous)
RAMAPURAM, CHENNAI-89
LAB MANUAL
REGULATIONS R23
ACADEMIC YEAR:2024-2025
Prepared By :
M.Sowmiya
P.Deepika
T.Saraswathi Approved By
HOD/IT
Vision
To impart Quality Education towards the holistic development of students and be a
Mission
To offer doctoral programmes in the field of Information Technology to enhance
M1
research activities.
To awaken the young minds and lay solid Engineering foundation among the
M2 graduates through the design of experiments, analysis and interpretation of data.
To prepare and build the ability to recognise the need for independent and
M7 lifelong learning in the context of technological changes in the field
of Information Technology.
`
LT PRC 0 04 02
COURSE OBJECTIVES
LIST OF EXPERIMENTS
TOTAL:60 PERIODS
Course Name: 231ITC311L- Data Structures Laboratory Year / Sem: 2023-2024/ III
TurboC IDE
Turbo C IDE facilitates editing, debugging and execution of applications written in C.C
programs are saved with .c extension.Some of the short cut keys are:
Ctrl+F1 Help
F2 Save
F3 Open
Copy Ctrl+Ins
Cut Shift+Del
Paste Shift+Ins
Clear Ctrl+Del
Alt+F9 Compile
Ctrl+F9 Execute
Alt+F5 UserScreen
F7 TraceInto
Alt+F3 Close
Alt+X Quit
Ex NO: 1 ARRAY IMPLEMENTATION OF LIST ADT
DATE :
Aim
To write a ‘C’ program to implement List ADT using arrays.
Algorithm
Step 1: Start.
Step 2: Declare the necessary functions for implementation.
Step 3: Get the input from the user and store it an array.
Step 4: In Insertion, half of the elements to be shifted upwards and in deletion, half of the elements
to
be shifted downwards.
Step 5: Display the output using an array.
Step 6: Stop the program execution.
Result
Thus, the ‘C’ program to implement the list ADT using arrays has been executed and the output is
verified successfully.
Ex NO: 2 ARRAY IMPLEMENTATION OF STACK
DATE :
Aim
Algorithm
Step 1: Start.
Step 3: Get the input from the user and store it an array.
Step 4: In Insertion, half of the elements to be shifted upwards and in deletion , half of the
elements to
be shifted downwards.
Step 5: Display the output using an array.
Step 6: Stop
Result
Thus the ‘C’ program to implement stack using arrays is executed and the output is verified
successfully.
Ex NO: 3
ARRAY IMPLEMENTATION OF QUEUE
DATE :
Aim
Algorithm
Aim
To write a program to implement the linked list using pointers.
Algorithm
Step 1: Start
Step 1: Include all the header files which are used in the program.
Step 2: Declare all the user defined functions.
Step 3: Define a Node structure with two members data and next
Step 4: Define a Node pointer 'head' and set it to NULL.
Step 4: Implement the main method by displaying operations menu and make suitable function calls
in
the main method to perform user selected operation.
Step 6: Stop
Insertion
In a single linked list, the insertion operation can be performed in three ways. They are as follows...
● Inserting At Beginning of the list
● Inserting At End of the list
● Inserting At Specific location in the list
● Inserting At Beginning of the list
The following steps to insert a new node at beginning of the single linked list...
The following steps to insert a new node at end of the single linked list...
Step 1: Create a newNode with given value and newNode → next as NULL.
Step 2: Check whether list is Empty (head == NULL).
Step 3: If it is Empty then, set head = newNode.
Step 4: If it is Not Empty then, define a node pointer temp and initialize with head.
Step 5: Keep moving the temp to its next node until it reaches to the last nodein the list (until
temp → next is equal to NULL).
Step 6: Set temp → next = newNode.
Deletion
In a single linked list, the deletion operation can be performed in three ways. They are as follows...
● Deleting from Beginning of the list
● Deleting from End of the list
● Deleting a Specific Node
● Deleting from Beginning of the list
The following steps to delete a node from beginning of the single linked list...
The following steps to delete a specific node from the single linked list...
Thus, the ‘C’ program to implement linked list using pointers has been executed and the output is
verified successfully.
Ex NO: 5
Aim:
To write a ‘C’ program to implement the linked list using stack ADT.
Algorithm
Thus the C program to implement the linked list using stack ADT has been executed and the
output is verified successfully.
Ex NO: 6 LINKED LIST IMPLEMENTATION OF QUEUE ADT
DATE :
Aim
To write a ‘C ‘program to implement linked list using Queue ADT.
Algorithm
Step1: Define a C-struct for each node in the queue. Each node in the queuecontains data and link to
the next node. Front and rear pointer points to first and last node inserted in the queue.
Step 2: The operations on the queue are
a. INSERT data into the queue
b. DELETE data out of queue
Step 3: INSERT DATA INTO queue
a.Enter the data to be inserted into queue.
b.If TOP is NULL then the input data is the first node in queue.The link of the node is NULL.
TOP points to that node.
c.If TOP is NOT NULL then the link of TOP points to the new node.TOP points to that node.
Step 4: DELETE DATA FROM queue
a. If TOP is NULL then the queue is empty
b. If TOP is NOT NULL then the link of TOP is the current TOP.pervious TOP is popped
from
queue.
Step 5: The queue represented by linked list is traversed to display its content.
Result
Thus the ‘C’program to implement the Queue using linked list has been executed and the output is
verified successfully.
Ex NO: 7.a
Aim
To write a C program to convert Infix to Postfix Expression.
Algorithm
1. Start the program
2. Using the strlen function determine the length of the string
3. Declare three arrays; the decremented value of one array is assigned to the incremented value.
This process is repeated until the parenthesis matches.
4. Until t==0 assign the values to sack1
5. Check if (top2==-1) if the condition is satisfied then assign stack2 [++top2]=str[i];
6. Print the result.
7. Stop the program
Result
Thus the ‘C’ program to convert Infix to Postfix Expression has been executed and the output
is verified successfully.
Ex NO: 7.b
APPLICATIONS OF QUEUE
DATE :
FCFS SCHEDULING ALGORITHM
Aim
Algorithm
Step 5: Start with the first process from it’s initial position let other process to be in queue
Thus the ‘C’ program to implement theFCFS scheduling algorithm has been executed and the output
is verified successfully.
Ex NO: 8
Aim
Algorithm
Step 1: Start
Step 2: Create a Binary Search Tree for N elements.
Step 3: Traverse the tree in inorder.
Step 4: Traverse the tree in preorder
Step 6: Traverse the tree in postorder.
Step 7: Search the given key element in the BST.
Step 8: Delete an element from BST.
Step 9: Stop
Result
Thus, the ‘C’ program to implement Binary search Tree has been executed and the output is verified
successfully.
Ex NO: 9
Aim
Algorithm
Thus the ‘C’ program to implement the AVL Tree has been executed and the output is verified
successfully.
Ex NO: 10 IMPLEMENTATION OF HEAPS USING
DATE : PRIORITY QUEUES
Aim
Algorithm
Step 1: Start
Step 2: Initialize all necessary variables and functions.
Step 3: Read the choices.
Step 4: For insertion, read the element to be inserted.
Step 5: If root is NULL, assign the given element as root.
Step 6: If the element is equal to the root, print “Duplicate value”.
Step 7: Else if element value is less than the root value, insert element at the left of the root.
Step 8: Else insert right side of the root.For deletion, get the priority for maximum or minimum.
Step 9: If maximum, it deletes the root and rearranges the tree.
Step 10: If minimum, it deletes the leaf.
Step 11:End of the program
Result
Thus, the ‘C’ program to implement Heaps using priority Queues been executed and the output is
verified successfully.
Ex NO: 11 IMPLEMENTATION OF GRAPH AND
DATE : TRAVERSAL ALGORITHMS
Aim
To write a ‘C’ program to implement Depth First Search (DFS) using Adjacency Matrix
representation of graph.
Algorithm
Step 1: Start by putting any one of the graph's vertices on top of a stack.
Step 2: Take the top item of the stack and add it to the visited list.
Step 3: Create a list of that vertex's adjacent nodes. Add the ones, which are not in the visited list to
the
top of stack.
Thus, the ‘C’program to implement Depth First Search (DFS) has been executed and the output is
verified successfully.
Ex NO: 12.a
IMPLEMENTATION OF BUBBLE SORT
DATE :
Aim
Algorithm
Thus the ‘C’ program to implement bubble sort has been executed and the output is verified
successfully.
Ex NO: 12.b
IMPLEMENTATION OF QUICK SORT
DATE :
Aim
Algorithm
Thus the ‘C’ program to implement Quick sort has been executed and the output is verified
successfully.
Ex NO: 13.a
IMPLEMENTATION OF LINEAR SEARCH
DATE :
Aim
Algorithm
Step 3: Start from the leftmost element of arr[] and one by one compare x with each element of arr[]
Thus the ‘C’ program to implement the Linear search has been executed and the output is
verified successfully.
Ex NO: 13.b
IMPLEMENTATION OF BINARY SEARCH
DATE :
Aim
Algorithm
Step 7: If the target is greater than mid then first is mid + 1 if not last is mid -1
Step 9: The target is found, if its equal to a(mid) otherwise target is not found.
Result
Thus the ‘C’ program to implement the binary search has been executed and the output is
verified successfully.
Ex NO: 14
HASHING – ANY TWO COLLISION TECHNIQUES
DATE :
Aim
Algorithm
Step 1: Create a structure, data (hash table item) with key and value as data.
Step 2: Now create an array of structure, data of some certain size. But, the size ofarraymust be
immediately updated to a prime number just greater than initial array
Step 3: A menu is displayed on the screen.
Step 4: User must choose one option from four choices given in the menu
Step 5: Perform all the operations
Step 6: Stop the program
Result
Thus the ‘C’ program to implement Hashing using Linear and Quadratic Probing has been executed and
the output is verified successfully.
Ex NO: 15 CONTENT BEYOND SYLLABUS
DATE : APPLICATIONS OF GRAPHS – DIJIKSTRA’S
ALGORITHM
Aim
Algorithm
Step 1 : Begin
Step 2: Create cost matrix C[ ][ ] from adjacency matrix adj[ ][ ]. C[i][j] is the cost of going from
vertex
i to vertex j. If there is no edge between vertices i and j then C[i][j] is infinity.
Step 5: Create the distance matrix, by storing the cost of vertices from vertex no. 0 to n-1 from the
source vertex 0.
for(i=1;i<n;i++)
distance[i]=cost[0][i];
Initially, distance of source vertex is taken as 0. i.e. distance[0]=0;
Step 6: for(i=1;i<n;i++)
– Choose a vertex w, such that distance[w] is minimum and visited[w] is 0. Mark visited[w]
as 1.
Recalculate the shortest distance of remaining vertices from the source.
– Only, the vertices not marked as 1 in array visited[ ] should be considered for recalculation
of
distance. i.e. for each vertex v
if(visited[v]==0)
distance[v]=min(distance[v],
distance[w]+cost[w][v])
Step 7: Return
Result
Thus, the ‘C’program to implement Dijikstra’s Algorithm has been executed and the output is
verified successfully.
Ex NO: 16 CONTENT BEYOND SYLLABUS
DATE : IMPLEMENTATION OF RADIX SORT
Aim
Algorithm
Step 2: In 1st pass,we sort the array on basis of least significant digit (1s place) using counting sort.
Step 3: In 2nd pass,we sort the array on basis of next digit (10s place) using counting sort.
Step 4: In 3rd pass,we sort the array on basis of most significant digit (100s place) using counting
sort.