Posts

Showing posts from April, 2024

Design & Analysis of Algorithm Practical Slips Programs

Design & Analysis of Algorithm Practical Slips Programs Slip 1  Write a program to sort a list of n numbers in ascending order using selection sort and determine the time required to sort the elements. #include <stdio.h> #include <stdlib.h> #include <time.h> void selectionSort(int arr[], int n) {     int i, j, minIndex, temp;     for (i = 0; i < n - 1; i++) {         minIndex = i;         for (j = i + 1; j < n; j++) {             if (arr[j] < arr[minIndex]) {                 minIndex = j;             }         }         // Swap arr[minIndex] and arr[i]         temp = arr[minIndex];         arr[minIndex] = arr[i];         arr[i] = temp;     } } int main() {     int n, i; ...