1dsa - Jaykishor
1dsa - Jaykishor
1dsa - Jaykishor
SA
NS
SESSION:2023-
2024
SUBMITTED
•Aim -- Write a program to create a array and search a number by the help
of linear search
#include<stdio.h>
int main(){
//Linear search
scanf("%d", &number);
scanf("%d", &arr[n]);
scanf("%d", &store);
break;
} }
return 0; }
OUTPUT:
Name – Tanish Tyagi Enrollment No. – 2202305106 Course – BTECH(CSE) [B]
Sanskriti University Sub-Data – Structure
EXPERIMENT:2
• Aim - Write a program to create a array and search a number by the help of
binary search
#include <stdio.h>
int i = 0;
int j = size - 1;
while (i <= j) {
int mid = i + (j - i) / 2;
if (arr[mid] == search) {
return mid;
i = mid + 1;
else {
j = mid - 1;
return 0; }
int main() {
scanf("%d", &size);
int arr[size];
scanf("%d", &arr[i]);
scanf("%d", &search);
if (result != -1) {
} else {
}
return 0;}
OUTPUT:
EXPERIMENT:3
• Aim -- Write a program to sort the unsorted array by the help of bubble sort
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
arr[j + 1] = temp;
} } }
return 0; }
OUTPUT:
EXPERIMENT:4
• Aim - Write a program to sort the unsorted array by the help of merge sort
#include <stdio.h>
void merge(int arr[], int left[], int leftSize, int right[], int rightSize) {
int i = 0, j = 0, k = 0;
arr[k] = left[i];
i++;
} else {
arr[k] = right[j];
j++;
k++;
}
// Copy the remaining elements of left[] and right[], if any
arr[k] = left[i];
i++;
k++;
}
while (j < rightSize) {
arr[k] = right[j];
j++;
k++;
if (size < 2) {
int left[mid];
left[i] = arr[i];
mergeSort(left, mid);
}
Name – Tanish Tyagi Enrollment No. – 2202305106 Course – BTECH(CSE) [B]
Sanskriti University Sub-Data – Structure
int main() {
int n;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
mergeSort(arr, n);
return 0; }
OUTPUT:
EXPERIMENT:5
• Aim -- Write a program to sort the unsorted array by the help of insertion sort
#include <stdio.h>
int i, j, key;
key = arr[i];
j = i - 1;
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);
return 0; }
OUTPUT:
EXPERIMENT:6
• Aim -- Write a program to sort the unsorted array by the help of selection sort
#include <stdio.h>
minIndex = i;
minIndex = j;
} }
temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
} }
int main() {
int n;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]); }
selectionSort(arr, n);
return 0; }
OUTPUT:
EXPERIMENT:7
• Aim -- Write a program to sort the unsorted array by the help of quick sort
#include <stdio.h>
// Function to partition the array into two subarrays and return the pivot index
arr[i] = arr[j];
arr[j] = temp;
arr[i + 1] = arr[high];
arr[high] = temp;
return i + 1; }
quickSort(arr, pi + 1, high);
} }
int main() {
int n;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]); }
quickSort(arr, 0, n - 1);
return 0; }
OUTPUT:
• Aim -- Write a program for performing the push and pop operation of the stack .
#include <stdio.h>
#define MAX_SIZE 5
int main()
{
int choice, num; // declared the variable
while (1)
{
printf("\n1. PUSH\n");
printf("2. POP\n");
printf("3. DISPLAY\n");
printf("4. EXIT\n");
printf("Enter your choice: ");
scanf("%d", &choice);
return 0;
}
Output:
EXPERIMENT:9
• Aim -- Write a program for performing the enqueue and dequeue operation of the
queue.
#include <stdio.h>
#define maxsize 5
int queue[maxsize];
int rear = -1, front = 0;
// Function prototypes
void insert(int n);
void display();
void delete();
int main() {
int choice,n;
do {
printf("\nEnter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 4);
return 0;
}
void insert(int n) {
if (rear == maxsize - 1) {
printf("\nQUEUE is full.\n");
} else {
rear++;
queue[rear] = n;
}
}
void display() {
if (front > rear) {
printf("\nQueue is empty.\n");
} else {
printf("\nQueue elements are: ");
for (int i = front; i <= rear; i++) {
printf("%d ", queue[i]);
}
printf("\n");
}
}
void delete() {
if (front > rear) {
printf("\nQueue is empty.\n");
} else {
int n = queue[front];
front++;
printf("The deleted element is %d.\n", n);
}
}
Output: