AOA Outputs
AOA Outputs
Input :-
// Main function
#include <stdio.h>
int main() {
// Function to perform Selection Sort
int arr[] = {64, 25, 12, 22, 11}; // Example
void selectionSort(int arr[], int n) { array
int i, j, minIndex, temp; int n = sizeof(arr) / sizeof(arr[0]);
// Traverse the array printf("Original array: \n");
for (i = 0; i < n - 1; i++) { printArray(arr, n);
// Assume the first element is the selectionSort(arr, n);
minimum
minIndex = i;
printf("\nSorted array: \n");
// Find the index of the smallest element
in the remaining array printArray(arr, n);
minIndex = j; }
} Output :-
temp = arr[minIndex];
arr[minIndex] = arr[i];
arr[i] = temp;
printf("\n");
}
Experiment No. 2 int mid = left + (right - left) / 2;
while (i < n1 && j < n2) { int arr[] = {64, 25, 12, 22, 11};
k++; return 0;
} }
arr[k] = L[i];
i++;
k++;
arr[k] = R[j];
j++;
k++;
}}
*a = *b; }
*b = temp; printf("]\n");
} return maxValue; }
if (W >= items[i].weight) {
W -= items[i].weight;
maxValue += items[i].value;
includedItems[index++] = i;
} else {
Experiment No. 4 totalProfit += jobs[i].profit;
}; printf("%d", selectedJobs[i]);
max = jobs[i].deadline; struct Job jobs2[] = {{1, 1, 50}, {2, 1, 40}, {3,
1, 30}};
return max;
int n2 = sizeof(jobs2) / sizeof(jobs2[0]);
}
printf("\nTest Case 2:\n");
void jobSequencing(struct Job jobs[], int n) {
jobSequencing(jobs2, n2);
qsort(jobs, n, sizeof(struct Job), compare); //
Sort jobs by profit return 0;
int totalProfit = 0;
if (slot[j] == -1) {
slot[j] = jobs[i].id;
Experiment No. 5 void inputCostMatrix() {
minCost = newCost;
void initializeMemo() {
memo[i][j] = -1;
}
Experiment No. 6
Input :- else
#include <string.h> }
if (i == 0 || j == 0) int main() {
L[i][j] = (L[i - 1][j] > L[i][j - 1]) ? L[i - 1][j] scanf("%s", Y);
: L[i][j - 1];
// Find and print LCS
}
findLCS(X, Y);
}
return 0;
int index = L[m][n];
}
char lcs[index + 1];
Output :-
lcs[index] = '\0';
int i = m, j = n;
i--;
j--;
index--;
i--;
Experiment No. 7 for (int i = 0; i < N; i++) { // Try placing a
queen in each row
Input :-
if (isSafe(i, col)) {
#include <stdio.h>
board[i][col] = 1; // Place queen
#include <stdbool.h>
res = solveNQueens(col + 1) || res; //
#define MAX 10 Try next column
void printSolution() { }}
// Function to check if it's safe to place a queen for (int j = 0; j < N; j++)
at board[row][col]
board[i][j] = 0;
bool isSafe(int row, int col) {
if (!solveNQueens(0))
int i, j;
printf("No solution exists\n");
for (i = 0; i < col; i++)
}
if (board[row][i])
int main() {
return false;
solve();
for (i = row, j = col; i >= 0 && j >= 0; i--, j--)
return 0; }
if (board[i][j])
Output :-
return false;
if (board[i][j])
return false;
return true; }
if (col >= N) {
printf("\n");
if (isSafe(v, c)) {
color[v] = 0; // Backtrack
return res; }
Experiment No. 9
Output :-
printf("Occurrences of pattern:\n");
int j;
if (text[i + j] != pattern[j]) {
// Driver function
int main() {
gets(text);
Experiment No. 10 int q = 101;
search(pat, txt, q);
#include <stdio.h> return 0;
#include <string.h> }
#define d 256
// Rabin-Karp Algorithm
void search(char pat[], char txt[], int q) {
int M = strlen(pat); // Length of pattern
int N = strlen(txt); // Length of text
int i, j;
int p = 0; // Hash value for pattern
int t = 0; // Hash value for text window
int h = 1;
// Compute h = (d^(M-1)) % q
for (i = 0; i < M - 1; i++)
h = (h * d) % q;
// Driver Code
int main() {
char txt[] = "PROGRAMMERS PROGRAM
WELL";
char pat[] = "PROG";