1dsa - Jay
1dsa - Jay
1dsa - Jay
it.]
, just drag
N
the page
w here on
IU
ox any
text b
MA
is
ce th
o pla
int. T
T
y po
a ke
I
ze
TH
p hasi
o em
ce t
R
spa
this
u or
use
SK U
e nt
um
oc
th
ed
m
fro
te
uo
tq
ea
r
ag
SAN it h
nw
RA
tio
en
att
er ’s
read
[Grab your
SESSION:2023-2024
SUBMITTED BY
EXPERIMENT:1
•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:
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 – Jaykishor singh Enrollment No. – 2202305039 Course – BTECH(CSE) [A]
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: