0% found this document useful (0 votes)
120 views22 pages

Lab Manual-Ds (AI&ML)

The document is a lab manual for the Data Structures Laboratory at Erode Sengunthar Engineering College, detailing the institution's vision and mission, program educational objectives, and program outcomes. It includes safety rules for the laboratory, guidelines for maintaining a laboratory notebook, and a list of experiments related to data structures. Additionally, it provides code examples for implementing various data structures such as stacks, queues, linked lists, and binary trees.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views22 pages

Lab Manual-Ds (AI&ML)

The document is a lab manual for the Data Structures Laboratory at Erode Sengunthar Engineering College, detailing the institution's vision and mission, program educational objectives, and program outcomes. It includes safety rules for the laboratory, guidelines for maintaining a laboratory notebook, and a list of experiments related to data structures. Additionally, it provides code examples for implementing various data structures such as stacks, queues, linked lists, and binary trees.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ERODE SENGUNTHAR

ENGINEERING COLLEGE
(An Autonomous Institution)
Approved by AICTE, New Delhi, Permanently Affiliated to Anna
University- Chennai, Accredited by National Board of
Accreditation (NBA), New Delhi &
National Assessment and Accreditation Council (NAAC), Bangalore with ‘A’ Grade
PERUNDURAI -638 057, TAMILNADU, INDIA.

DEPARTMENT OF CSE(AI&ML)

23CD301 DATA STRCUTURES LABORATORY

LAB MANUAL

Prepared by
Ms.N.Krishnaveni AP/CSE(AI&ML)

INSTITUTE VISION
Vision of Erode Sengunthar Engineering College is to become a World Class Technical
Institution and Scientific Research Centre for the Benefit of the Society.

INSTITUTE MISSION

Erode Sengunthar Engineering College will strive continuously to


 Create Positive difference to Society through Innovative Teaching – Learning Process.
 Impart Value Based Technical Education to the Students from across various Socio
Economic backgrounds.
 Build State of art infrastructure for high quality Research and Development capabilities on
par with the finest in the Globe and widen student’s horizons beyond Class Room.
 Bring out Competent, Ethically Strong and Quality Professionals.

Vision
Empowering a future where Artificial Intelligence and Machine Learning redefine the
boundaries of innovation, enhancing human potential and fostering a world where intelligent
technologies seamlessly collaborate with humanity for unprecedented advancements.

Mission
 To empower individuals and organizations with the knowledge, skills, and ethical principles essential
for unlocking the transformative power of Artificial Intelligence and Machine Learning.
 To foster a vibrant community of innovators, researchers, and practitioners who collaborate
passionately to develop intelligent systems.
These systems are not only capable of addressing real-world challenges but also contribute
significantly to advancing the collective well-being of humanity.

 PEO 1: To be able to solve wide range of Artificial intelligence and Machine Learning related
problems to cater to the needs of industry and society
 PEO 2: Excel with professional skills, fundamental knowledge, and advanced futuristic technologies
to become Data Scientists, Machine Learning leaders AI Research Scientists or Entrepreneurs
 PEO 3: Produce graduates having professional competence through life-long learning such as
advanced degrees, and professional skills related globally to engineering & society
 PEO 4: Develop code and solutions for the industry in a rapidly changing technology environment
and communicate with clients as an entrepreneur

PROGRAM OUTCOMES (PO)


PO1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering problems.
PO2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
PO3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate consideration
for the public health and safety, and the cultural, societal, and environmental considerations.
PO4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
PO5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
PO7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
PO8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
PO10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive clear
instructions.
PO11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and leader
in a team, to manage projects and in multidisciplinary environments.
PO12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
Program Specific Outcomes (PSO)
PSO 1: Should have an ability to apply technical knowledge and usage of modern hardware and
software tools related AI and ML for solving real-world problems.
PSO 2: To create, and apply the techniques of AI and Machine Learning to forecast future events in
the domain of Healthcare, Education, and Agriculture, Manufacturing, Automation, Robotics,
Transport etc.
PSO 3: Enrich their abilities to qualify for Employment in the field of AI and ML.
LABORATORY PRACTICE

SAFETY RULES

To ensure a safe and productive environment in the Computer Science and Design
Laboratory, follow these safety rules:

General Safety Guidelines

1. Authorized Access Only – Enter the lab only with permission from the instructor or
lab supervisor.
2. No Food or Drinks – Keep food, drinks, and water bottles away from computers and
electronic equipment to prevent damage and electrical hazards.
3. Proper Handling of Equipment – Use all computers, peripherals, and design tools
carefully and as instructed. Do not attempt to open or modify hardware without
authorization.
4. Neat and Organized Workspace – Keep cables, devices, and workstations organized
to avoid tripping hazards or accidental damage.

Electrical and Fire Safety

5. Check Power Cords and Sockets – Do not overload power outlets. Report any
damaged cords, exposed wires, or faulty equipment immediately.
6. Turn Off Equipment – Shut down computers and other devices properly after use.
Unplug equipment if necessary when instructed.
7. Emergency Procedures – Familiarize yourself with fire extinguishers, emergency
exits, and evacuation plans in case of a fire or power failure.

Cyber and Data Safety

8. Use Strong Passwords – Keep your login credentials secure and do not share them
with others.
9. No Unauthorized Software Installation – Do not install or download software
without permission to prevent malware and security risks.
10. Backup Important Data – Save work regularly and maintain backups to avoid data
loss.

Ergonomic and Personal Safety

11. Proper Sitting Posture – Adjust chair height and screen position to reduce strain on
the eyes, neck, and back.
12. Take Breaks – Follow the 20-20-20 rule: every 20 minutes, look 20 feet away for 20
seconds to reduce eye strain.
13. Avoid Overloading Machines – Running too many programs at once may cause
system crashes or overheating.

Guidelines for Laboratory Notebook

Title

 Each page should include the lab exercise or project title along with an
identification number if applicable.

Objective

 Provide a brief but clear statement explaining what you aim to develop, analyze, or
verify in the lab exercise.

System Architecture / Flow Diagram

 Include a flowchart, system architecture, or block diagram to illustrate the logical


structure of the implementation.
 Clearly label each component for better understanding.

Software & Hardware Requirements

 List the software tools, programming languages, libraries, and hardware


components used.
 Mention specific versions if applicable, as they may impact the outcome.

Code & Implementation

 Record important code snippets, configurations, or commands used during the


exercise.
 If the code is lengthy, attach a reference and note its location.

Data Collection & Outputs

 Use tables to record raw data, outputs, error messages, and logs generated during
execution.
 Avoid using only processed results—document actual system outputs before any
modifications.

Observations & Inferences


 Note any challenges faced, unexpected results, or errors encountered during
execution.
 Provide insights on how the implementation can be improved or optimized.

S.No LIST OF EXPERIMENTS


1 Array Implementation of Stack and Queue ADTs
2 Array Implementation of List ADT
3 Linked list implementation of List, Stack and Queue ADTs
4 Applications of List, Stack and Queue ADTs
5 Implementation of Binary Trees and operations of Binary Trees
6 Implementation of Binary Search Trees
7 Graph representation and Traversal Algorithms
8 Implementation of searching and sorting algorithms

Array Implementation of StackADT

#include<stdio.h>
#include<stdlib.h>
int size,stack[20],top=-1;
void push();
void pop();
void display();
int main()def
{
int choice;
scanf("%d",&size);
do
{
scanf("%d",&choice);
switch(choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
printf("Exited");
exit(0);
}
}while(1);
}
void push()
{
int n;
scanf("%d",&n);
if(top==size-1)
printf("Stack Overflow : Stack is Full\n");
else
{
printf("Item %d is pushed\n",n);
++top;
stack[top]=n;
}
}
void pop()
{
if(top==-1)
printf("Stack Underflow : No Item in the Stack\n");
else
{
printf("Item %d is popped\n",stack[top]);
top--;
}
}
void display()
{
if(top==-1)
printf("Stack Underflow: No item in the Stack\n");
else
{
printf("The Stack Contents are\n");
for(int i=top;i>=0;i--)
printf("%d\n",stack[i]);

}
}
Array Implementation of List ADT
Singly Linked List
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node* next;
};
struct Node* createNode(int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;
return newNode;
}

void insertAtFirst(struct Node** head, int data) {


struct Node* newNode = createNode(data);
newNode->next = *head;
*head = newNode;
}

void insertAtEnd(struct Node** head, int data) {


struct Node* newNode = createNode(data);
if (*head == NULL) {
*head = newNode;
return;
}
struct Node* temp = *head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = newNode;
}

void insertAtPosition(struct Node** head, int data, int position) {


struct Node* newNode = createNode(data);
if (position == 0) {
insertAtFirst(head,data);
return;
}
struct Node* temp = *head;
for (int i = 0; temp != NULL && i < position - 1; i++) {
temp = temp->next;
}
if (temp == NULL) {
printf("Position out of range\n");
free(newNode);
return;
}
newNode->next = temp->next;
temp->next = newNode;
}

void deleteFromFirst(struct Node** head) {


if (*head == NULL) {
printf("List is empty\n");
return;
}
struct Node* temp = *head;
*head = temp->next;
free(temp);
}

void deleteFromEnd(struct Node** head) {


if (*head == NULL) {
printf("List is empty\n");
return;
}
struct Node* temp = *head;
if (temp->next == NULL) {
free(temp);
*head = NULL;
return;
}
while (temp->next->next != NULL) {
temp = temp->next;
}
free(temp->next);
temp->next = NULL;
}

void deleteAtPosition(struct Node** head, int position) {


if (*head == NULL) {
printf("List is empty\n");
return;
}
struct Node* temp = *head;
if (position == 0) {
deleteFromFirst(head);
return;
}
for (int i = 0; temp != NULL && i < position - 1; i++) {
temp = temp->next;
}
if (temp == NULL || temp->next == NULL) {
printf("Position out of range\n");
return;
}
struct Node* next = temp->next->next;
free(temp->next);
temp->next = next;
}

void print(struct Node* head)


{
struct Node* temp = head;
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}

int main()
{
struct Node* head = NULL;

insertAtFirst(&head, 10);
printf("Linked list after inserting the node:10 at the beginning \n");
print(head);

printf("Linked list after inserting the node:20 at the end \n");


insertAtEnd(&head, 20);
print(head);

printf("Linked list after inserting the node:5 at the end \n");


insertAtEnd(&head, 5);
print(head);

printf("Linked list after inserting the node:30 at the end \n");


insertAtEnd(&head, 30);
print(head);

printf("Linked list after inserting the node:15 at position 2 \n");


insertAtPosition(&head, 15, 2);
print(head);

printf("Linked list after deleting the first node: \n");


deleteFromFirst(&head);
print(head);

printf("Linked list after deleting the last node: \n");


deleteFromEnd(&head);
print(head);

printf("Linked list after deleting the node at position 1: \n");


deleteAtPosition(&head, 1);
print(head);

return 0;
}
Doubly Linked List
// C Program to Implement Doubly Linked List
#include <stdio.h>
#include <stdlib.h>

// defining a node
typedef struct Node {
int data;
struct Node* next;
struct Node* prev;
} Node;

// Function to create a new node with given value as data


Node* createNode(int data)
{
Node* newNode = (Node*)malloc(sizeof(Node));
newNode->data = data;
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}

// Function to insert a node at the beginning


void insertAtBeginning(Node** head, int data)
{
// creating new node
Node* newNode = createNode(data);

// check if DLL is empty


if (*head == NULL) {
*head = newNode;
return;
}
newNode->next = *head;
(*head)->prev = newNode;
*head = newNode;
}

// Function to insert a node at the end


void insertAtEnd(Node** head, int data)
{
// creating new node
Node* newNode = createNode(data);

// check if DLL is empty


if (*head == NULL) {
*head = newNode;
return;
}

Node* temp = *head;


while (temp->next != NULL) {
temp = temp->next;
}
temp->next = newNode;
newNode->prev = temp;
}

// Function to insert a node at a specified position


void insertAtPosition(Node** head, int data, int position)
{
if (position < 1) {
printf("Position should be >= 1.\n");
return;
}

// if we are inserting at head


if (position == 1) {
insertAtBeginning(head, data);
return;
}
Node* newNode = createNode(data);
Node* temp = *head;
for (int i = 1; temp != NULL && i < position - 1; i++) {
temp = temp->next;
}
if (temp == NULL) {
printf(
"Position greater than the number of nodes.\n");
return;
}
newNode->next = temp->next;
newNode->prev = temp;
if (temp->next != NULL) {
temp->next->prev = newNode;
}
temp->next = newNode;
}
// Function to delete a node from the beginning
void deleteAtBeginning(Node** head)
{
// checking if the DLL is empty
if (*head == NULL) {
printf("The list is already empty.\n");
return;
}
Node* temp = *head;
*head = (*head)->next;
if (*head != NULL) {
(*head)->prev = NULL;
}
free(temp);
}

// Function to delete a node from the end


void deleteAtEnd(Node** head)
{
// checking if DLL is empty
if (*head == NULL) {
printf("The list is already empty.\n");
return;
}

Node* temp = *head;


if (temp->next == NULL) {
*head = NULL;
free(temp);
return;
}
while (temp->next != NULL) {
temp = temp->next;
}
temp->prev->next = NULL;
free(temp);
}

// Function to delete a node from a specified position


void deleteAtPosition(Node** head, int position)
{
if (*head == NULL) {
printf("The list is already empty.\n");
return;
}
Node* temp = *head;
if (position == 1) {
deleteAtBeginning(head);
return;
}
for (int i = 1; temp != NULL && i < position; i++) {
temp = temp->next;
}
if (temp == NULL) {
printf("Position is greater than the number of "
"nodes.\n");
return;
}
if (temp->next != NULL) {
temp->next->prev = temp->prev;
}
if (temp->prev != NULL) {
temp->prev->next = temp->next;
}
free(temp);
}

// Function to print the list in forward direction


void printListForward(Node* head)
{
Node* temp = head;
printf("Forward List: ");
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
printf("\n");
}

// Function to print the list in reverse direction


void printListReverse(Node* head)
{
Node* temp = head;
if (temp == NULL) {
printf("The list is empty.\n");
return;
}
// Move to the end of the list
while (temp->next != NULL) {
temp = temp->next;
}
// Traverse backwards
printf("Reverse List: ");
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->prev;
}
printf("\n");
}

int main()
{
Node* head = NULL;

// Demonstrating various operations


insertAtEnd(&head, 10);
insertAtEnd(&head, 20);
insertAtBeginning(&head, 5);
insertAtPosition(&head, 15, 2); // List: 5 15 10 20

printf("After Insertions:\n");
printListForward(head);
printListReverse(head);

deleteAtBeginning(&head); // List: 15 10 20
deleteAtEnd(&head); // List: 15 10
deleteAtPosition(&head, 2); // List: 15

printf("After Deletions:\n");
printListForward(head);

return 0;
}

You might also like