AOA Lab Programs
AOA Lab Programs
Q1. Implement recursive linear and binary search and determine the time
required to search an element. Repeat the experiment for different values of n,
the number of elements in the list to be searched and the time taken versus n.
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
#include <time.h>
int main()
{
int i, n, temp, choice;
int clrscr();
time_t start, end;
printf("\nEnter the number of elements: ");
scanf("%d",&n);
case 2:
start = time(NULL);
pos = n - 1;
temp = lin();
end = time(NULL);
break;
default:
printf("Invalid Input!!!");
break;
}
Output:
Q2. Sort a given set of elements using selection sort method and determine the
time required to sort the elements. Repeat the experiment for different values of
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int n,i;
return 0;
}
Output:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int n;
return 0;
}
Output:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int n;
return 0;
}
Output:
Q5. Sort a given set of elements using heap sort method and determine the
time required to sort the elements. Repeat the experiment for different values of
n, the number of elements in the list to be sorted and the time taken versus n.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int n;
return 0;
}
Output:
Q6. Find the minimum cost spanning tree of a given undirected graph using
Kruskal's algorithm.
#include <stdio.h>
#include <stdlib.h>
int main() {
int V, E;
// Input edges
printf("Enter the edges (src dest weight):\n");
for (int i = 0; i < E; i++) {
scanf("%d %d %d", &edges[i].src, &edges[i].dest, &e
dges[i].weight);
}
return 0;
}
Output:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main() {
int V;
int graph[MAX_VERTICES][MAX_VERTICES];
return 0;
}
Output:
#include <stdio.h>
int main() {
int n, capacity;
int weights[MAX_ITEMS], values[MAX_ITEMS];
Output:
Q9. From a given vertex in a weighted connected graph, find shortest paths to
other vertices using Dijkstra's algorithm.
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main() {
int V;
int graph[MAX_VERTICES][MAX_VERTICES];
int source;
printf("Enter the source vertex (0 to %d): ", V - 1);
scanf("%d", &source);
return 0;
}
#include <stdio.h>
#include <stdbool.h>
return true;
}
int main() {
int n;
printf("Enter the number of queens (N): ");
scanf("%d", &n);
if (solveNQueens(board, 0, n)) {
printf("One of the possible solutions is:\n");
printBoard(n);
} else {
printf("No solution exists for %d queens.\n", n);
}
return 0;
}
Output: