School of Computing Gehu, Bhimtal: Lab File
School of Computing Gehu, Bhimtal: Lab File
GEHU, BHIMTAL
Lab File
This is to certify that Mahi Pandey has satisfactorily completed all the
experiment in the laboratory of this college. The Term Work of Design
and Analysis of Algorithms Laboratory. In partial fulfilment of the
requirement in 4th semester of Bachelor of Computer Applications
degree course prescribed by Graphic Era Hill University, Bhimtal.
#include <stdio.h>
int main() {
int arr[] = {5, 3, 7, 9, 2, 4};
int target = 7;
int size = sizeof(arr) / sizeof(arr[0]);
int result = linear_search(arr, target, 0, size);
if (result != -1) {
printf("Element found at index %d\n", result);
} else {
printf("Element not found\n");
}
return 0;
Output:
Algorithm 2:
Program 2
#include <stdio.h>
return -1;
if (arr[mid] == target) {
return mid;
} else {
}
int main() {
int target = 7;
if (result != -1) {
} else {
return 0;
}
Output:
Algorithm 3:
Program 3
#include <stdio.h>
int main() {
int a = 56, b = 98;
printf("GCD of %d and %d is %d\n", a, b, gcd(a, b));
return 0;
}
Output:
Algorithm 4:
Program 4
#include <stdio.h>
int main() {
int n = 3;
printf("Tower of Hanoi solution for %d disks:\n", n);
towerOfHanoi(n, 'A', 'B', 'C');
return 0;
}
Output:
Algorithm 5:
Program 5
#include <stdio.h>
int i = 0, j = 0, k = left;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
int main() {
int arr[] = {12, 11, 13, 5, 6, 7};
int size = sizeof(arr) / sizeof(arr[0]);
merge_sort(arr, 0, size - 1);
for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
return 0;
}
Output:
Algorithm 6:
Program 6
#include <stdio.h>
int main() {
int arr[] = {10, 7, 8, 9, 1, 5};
int size = sizeof(arr) / sizeof(arr[0]);
Output :