Ssn
Ssn
REV.00DATE20.03.2020
RECORD NOTEBOOK
2024-2025(ODD SEMESTER)
DEPARTMENT
OF
REG NO : 231211101517
COURESE : B. Tech-CSE(AI)
YEAR/SEM/SEC : II/III/BF
FORM NO-F/TL/021
REV.00DATE20.03.2020
BONAFIDE CERTIFICATE
REGISTER NO : 231211101517
NAME OF LAB : DATA STRUCTURES LAB (EBCS22L01)
DEPATMENT : COMPUTER SCIENCE AND ENGINEERING
AIM:
ALGORITHM:
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int data[MAX_SIZE];
int size;
} List;
list->size = 0;
list->data[list->size] = element;
list->size++;
} else {
int found = 0;
if (list->data[i] == element) {
found = 1;
list->size--;
break;
if (!found) {
if (list->size == 0) {
printf("List is empty.\n");
return;
printf("\n");
int main() {
List myList;
initList(&myList);
do {
printf("\nMenu:\n");
printf("5. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &element);
addElement(&myList, element);
break;
case 2:
removeElement(&myList, element);
break;
case 3:
displayList(&myList);
break;
case 4:
break;
case 5:
printf("Exiting...\n");
break;
default:
return 0;
}
OUTPUT:
Figure:1a.2
Figure:1a.3
RESULT:
EX.NO:1B DATE:30/9/24
IMPLEMENT THE LIST ATD USING THE LINKED LIST
AIM:
ALGORITHM :
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int data;
} Node;
Node* head;
} List;
list->head = NULL;
if (!newNode) {
exit(1);
newNode->data = data;
newNode->next = NULL;
return newNode;
newNode->next = list->head;
list->head = newNode;
if (list->head == NULL) {
list->head = newNode;
return;
temp = temp->next;
temp->next = newNode;
list->head = temp->next;
free(temp);
return;
}
prev = temp;
temp = temp->next;
if (temp == NULL) {
return;
prev->next = temp->next;
free(temp);
if (temp->data == value) {
return 1;
temp = temp->next;
return 0;
}
void displayList(List* list) {
if (temp == NULL) {
printf("List is empty\n");
return;
printf("List: ");
temp = temp->next;
printf("NULL\n");
int main() {
List list;
initList(&list);
insertAtBeginning(&list, 10);
insertAtBeginning(&list, 20);
insertAtEnd(&list, 30);
insertAtEnd(&list, 40);
printf("After insertions:\n");
displayList(&list);
deleteNode(&list, 20);
printf("After deletion:\n");
displayList(&list);
if (search(&list, value)) {
} else {
return 0;
}
OUTPUT:
Figure:1b.2
RESULT:
EX.NO.2A: DATE:7/10/24
AIM:
ALGORITHM:
PROGRAM:
#include <stdio.h>
typedef struct {
int arr[MAX];
int top;
} Stack;
stack->top = -1;
if (isFull(stack)) {
return;
}
stack->arr[++stack->top] = value;
if (isEmpty(stack)) {
return stack->arr[stack->top--];
if (isEmpty(stack)) {
printf("Stack is empty!\n");
return stack->arr[stack->top];
if (isEmpty(stack)) {
printf("Stack is empty!\n");
return;
printf("\n");
int main() {
Stack stack;
initialize(&stack);
push(&stack, 10);
push(&stack, 20);
push(&stack, 30);
display(&stack);
return 0;
}
OUTPUT:
Figure:2a.b
RESULT:
EX.NO:2B DATE:7/10/24
AIM:
ALGORITHM:
PROGRAM:
#include <stdio.h>
#include <stdio.h>
typedef struct {
int arr[MAX];
int front;
int rear;
} Queue;
queue->front = -1;
queue->rear = -1;
}
// Function to enqueue an element into the queue
if (isFull(queue)) {
return;
if (isEmpty(queue)) {
queue->front = 0;
queue->arr[++queue->rear] = value;
if (isEmpty(queue)) {
if (queue->front == queue->rear) {
queue->front = -1;
queue->rear = -1;
} else {
queue->front++;
return value;
if (isEmpty(queue)) {
printf("Queue is empty!\n");
return queue->arr[queue->front];
if (isEmpty(queue)) {
printf("Queue is empty!\n");
return;
printf("\n");
}
int main() {
Queue queue;
initialize(&queue);
enqueue(&queue, 10);
enqueue(&queue, 20);
enqueue(&queue, 30);
display(&queue);
return 0;
}
OUTPUT:
Figure2b.2
RESULT:
EX.NO:3A DATE:14/10/24
AIM:
ALGORITHM:
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
struct Stack {
};
stack->top = NULL;
return stack;
newNode->data = item;
newNode->next = stack->top;
stack->top = newNode;
if (isEmpty(stack)) {
printf("Stack is empty\n");
stack->top = stack->top->next;
free(temp);
return poppedItem;
if (isEmpty(stack)) {
printf("Stack is empty\n");
return stack->top->data;
if (isEmpty(stack)) {
printf("Stack is empty\n");
return;
current = current->next;
printf("\n");
int main() {
printf("& .\n");
push(stack, 10);
push(stack, 20);
push(stack, 30);
display(stack);
display(stack);
return 0;
}
OUTPUT:
Figure:3a.2
RESULT:
EX NO.3B DATE:14/10/24
AIM:
ALGORITHM:
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
// Node structure
struct Node {
int data;
};
// Queue structure
struct Queue {
};
if (!newNode) {
exit(1);
newNode->data = data;
newNode->next = NULL;
return newNode;
if (!queue) {
exit(1);
return queue;
// Enqueue operation
if (queue->rear == NULL) {
return;
queue->rear->next = newNode;
queue->rear = newNode;
// Dequeue operation
return -1;
queue->front = queue->front->next;
if (queue->front == NULL)
queue->rear = NULL;
free(temp);
return data;
if (queue->front == NULL) {
printf("Queue is empty.\n");
return;
printf("Queue: ");
while (temp) {
temp = temp->next;
printf("\n");
// Main function
int main() {
do {
printf("\nQueue Operations:\n");
printf("1. Enqueue\n");
printf("2. Dequeue\n");
printf("3. Display\n");
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
enqueue(queue, value);
break;
case 2:
dequeue(queue);
case 3:
displayQueue(queue);
break;
case 4:
printf("Exiting program.\n");
break;
default:
// Free memory
dequeue(queue);
free(queue);
return 0;
figure:3b.2
RESULT :
AIM:
ALGORITHM:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
// Stack structure
typedef struct {
char data[MAX];
int top;
} Stack;
// Stack functions
s->top = -1;
if (!isFull(s)) {
s->data[++(s->top)] = ch;
} else {
printf("Stack Overflow\n");
if (!isEmpty(s)) {
return s->data[(s->top)--];
} else {
printf("Stack Underflow\n");
return '\0';
if (!isEmpty(s)) {
return s->data[s->top];
} else {
return '\0';
// Utility functions
switch (op) {
case '+':
case '*':
default: return 0;
Stack stack;
initStack(&stack);
int i = 0, j = 0;
postfix[j++] = infix[i];
push(&stack, infix[i]);
postfix[j++] = pop(&stack);
}
postfix[j++] = pop(&stack);
push(&stack, infix[i]);
i++;
while (!isEmpty(&stack)) {
postfix[j++] = pop(&stack);
int main() {
infixToPostfix(infix, postfix);
printf("Postfix expression: %s\n", postfix);
return 0;
}
OUTPUT:
Figure:4a.2
Figure:4a.3
RESULT:
EXPNO: 4b DATE:28/10/24
AIM:
ALGORITHM:
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
// Stack structure
typedef struct {
int data[MAX];
int top;
} Stack;
// Stack functions
s->top = -1;
s->data[++(s->top)] = value;
if (!isEmpty(s)) {
return s->data[(s->top)--];
} else {
printf("Stack Underflow\n");
exit(EXIT_FAILURE);
Stack stack;
initStack(&stack);
int i = 0;
if (isdigit(postfix[i])) { // Operand
} else { // Operator
switch (postfix[i]) {
}
i++;
return pop(&stack);
int main() {
char postfix[MAX];
scanf("%s", postfix);
return 0; }
OUTPUT:
Figure4b.2
RESULT:
EXPNO: 05 DATE:04/11/24
BINARY TREE TRAVERSAL IN ORDER ,PREORDER,
POSTORDER USING RECURSION
AIM:
ALGORITHM:
// Pre-order traversal (Root, Left, Right)
if (root != NULL) {
if (root != NULL) {
int main() {
int n, data;
scanf("%d", &n);
scanf("%d", &data);
node = newNode(data);
if (root == NULL) {
} else {
temp = root;
while (1) {
if (temp->left == NULL) {
temp->left = node;
break;
} else {
temp = temp->left;
} else {
if (temp->right == NULL) {
temp->right = node;
break;
} else {
temp = temp->right;
inOrder(root);
preOrder(root);
postOrder(root);
return 0;
}
OUTPUT:
Figure:5b.2
RESULT:
EXPNO:06 DATE:11/11/24
AIM:
ALGORITHM:
CODE:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
node->data = data;
return node;
if (root == NULL) {
return newNode(data);
return root;
return root;
current = current->left;
return current;
if (root == NULL) {
return root;
} else {
if (root->left == NULL) {
free(root);
return temp;
free(root);
return temp;
root->data = temp->data;
return root;
}
// In-order traversal of the BST
if (root != NULL) {
inOrder(root->left);
inOrder(root->right);
if (root != NULL) {
preOrder(root->left);
preOrder(root->right);
if (root != NULL) {
postOrder(root->left);
postOrder(root->right);
}
int main() {
scanf("%d", &n);
scanf("%d", &data);
printf("\nChoose operation:\n");
scanf("%d", &choice);
switch (choice) {
case 1:
inOrder(root);
break;
case 2:
preOrder(root);
break;
case 3:
postOrder(root);
break;
case 4:
scanf("%d", &key);
if (found != NULL) {
} else {
break;
case 5:
scanf("%d", &key);
default:
printf("Invalid choice.\n");
return 0;
}
OUTPUT:
Figure:6.2
RESULT:
EXPNO: 07 DATA:25/11/24
IMPLEMENTATION OF BINARY HEAPS
AIM:
ALGORITHM:
CODE:
#include <stdio.h>
#include <stdlib.h>
int heap[MAX];
int heapSize = 0;
*a = *b;
*b = temp;
largest = left;
largest = right;
if (largest != index) {
swap(&heap[index], &heap[largest]);
heapifyDown(largest);
swap(&heap[index], &heap[parent]);
heapifyUp(parent);
if (heapSize == MAX) {
printf("Heap overflow!\n");
return;
heap[heapSize] = value;
heapifyUp(heapSize);
heapSize++;
}
// Delete the root (maximum element) from the heap
void deleteRoot() {
if (heapSize == 0) {
printf("Heap underflow!\n");
return;
heapSize--;
heapifyDown(0);
void printHeap() {
if (heapSize == 0) {
printf("Heap is empty!\n");
return;
printf("\n");
}
int main() {
while (1) {
printf("1. Insert\n");
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
insert(value);
break;
case 2:
deleteRoot();
break;
case 3:
printHeap();
break;
case 4:
exit(0);
default:
return 0;
}
OUTPUT:
Figure:7.2
RESULT:
EXPNO:8a DATE:2/12/24
IMPLEMENTATION OF BREADTH FIRST SEARCH
AIM:
ALGORITHM:
CODE:
#include <stdio.h>
#include <stdlib.h>
if (rear == MAX - 1) {
printf("Queue Overflow\n");
return;
if (front == -1) {
front = 0;
queue[++rear] = node;
int dequeue() {
printf("Queue Underflow\n");
return -1;
}
return queue[front++];
int isQueueEmpty() {
// BFS function
enqueue(startNode);
visited[startNode] = 1;
while (!isQueueEmpty()) {
enqueue(i);
visited[i] = 1;
printf("\n");
}
int main() {
scanf("%d", &n);
scanf("%d", &edges);
visited[i] = 0;
graph[i][j] = 0;
graph[u][v] = 1;
scanf("%d", &startNode);
bfs(startNode, n);
return 0;
}
OUTPUT:
Figure:8a.2
RESULT:
EXPENO:8b DATE:16/12/24
AIM:
ALGORITHM:
CODE:
#include <stdio.h>
#include <stdlib.h>
int main() {
scanf("%d", &n);
scanf("%d", &edges);
// Initialize graph and visited array
visited[i] = 0;
graph[i][j] = 0;
graph[u][v] = 1;
scanf("%d", &startNode);
printf("\n");
return 0;
}
OUTPUT:
Figure:8b.2
RESULT:
EXPNO: 9a DATE:16/12/24
AIM:
ALGORITHM:
CODE:
#include <stdio.h>
if (arr[mid] == target) {
} else {
int main() {
int n, target;
scanf("%d", &n);
int arr[n];
scanf("%d", &target);
if (result != -1) {
} else {
return 0;
}
OUTPUT:
figure:9a.2
RESULT:
EXPNO:9B DATE:23/12/24
AIM:
ALGORITHUM:
CODE:
include <stdio.h>
if (arr[i] == target) {
int main() {
int n, target;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
scanf("%d", &target);
int result = linearSearch(arr, n, target);
if (result != -1) {
} else {
return 0;
}
OUTPUT:
Figure:9b.2
RESULT:
EXPNO: 10a DATE:23/12/24
BUBBLE SORT
Aim:
Algorithm:
CODE:
#include <stdio.h>
arr[j + 1] = temp;
if (!swapped) {
int main() {
int n;
printf("& .\n");
int arr[n];
scanf("%d", &arr[i]);
bubbleSort(arr, n);
printf("\n");
return 0;
}
OUTPUT:
Figure:10b
RESULT:
EXPNO: 10b DATE:30/12/24
SHELL SORT
AIM:
ALGORITHM:
CODE:
#include <stdio.h>
int j;
arr[j] = temp;
int main() {
int n;
printf("& .\n");
scanf("%d", &n);
int arr[n];
shellSort(arr, n);
printf("\n");
return 0;
}
OUTPUT:
Figure:10b.2
RESULT:
EXPNO: 10c DATE:30/12/24
INSERTION SORT
AIM:
ALGORITHM:
CODE:
#include <stdio.h>
int j = i - 1;
// Move elements of arr[0..i-1], that are greater than key, one position ahead
arr[j + 1] = arr[j];
j--;
arr[j + 1] = key;
int main() {
int n;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
}
insertionSort(arr, n);
printf("\n");
return 0;
}
OUTPUT:
Figure:10c.1
RESULT:
EXPNO: 10d DATE:6/1/25
AIM:
ALGORITHM:
CODE:
#include <stdio.h>
largest = left;
largest = right;
if (largest != i) {
arr[i] = arr[largest];
arr[largest] = temp;
heapify(arr, n, largest);
}
// Main function to perform heap sort
heapify(arr, n, i);
arr[0] = arr[i];
arr[i] = temp;
heapify(arr, i, 0);
int main() {
int n;
scanf("%d", &n);
int arr[n];
heapSort(arr, n);
printf("\n");
return 0;
}
OUTPUT:
Figure10d.1
RESULT:
EXPE:11 DATE:6/1/25
Aim:
Algorithm:
CODE:
#include <stdio.h>
#define TABLE_SIZE 10
int hashTable[TABLE_SIZE];
// Initialize hash table
void initialize() {
for (int i = 0; i < TABLE_SIZE; i++) {
hashTable[i] = -1;
}
}
// Primary hash function
int h1(int key) {
return key % TABLE_SIZE;
}
// Secondary hash function
int h2(int key) {
return 1 + (key % (TABLE_SIZE - 1));
}
// Insert key using double hashing
void insert(int key) {
int index = h1(key);
int step = h2(key);
int i = 0;
Figure:11.2
RESULT:.
CODE:
#include <stdio.h>
#define TABLE_SIZE 10
int hashTable[TABLE_SIZE];
void initialize() {
hashTable[i] = -1;
int i = 0;
i++;
if (i == TABLE_SIZE) {
return;
int i = 0;
i++;
if (i == TABLE_SIZE) break;
}
return -1; // Key not found
void display() {
if (hashTable[i] != -1)
else
int main() {
initialize();
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &key);
insert(key);
break;
case 2:
scanf("%d", &key);
if (result != -1)
else
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice\n");
return 0;
}
OUTPUT:
Figure:11.2
RESULT:.