0% found this document useful (0 votes)
3 views2 pages

Program 9 Seletion Sort

The document outlines an experiment to design and implement a C program that sorts a set of integers using the Selection Sort method and measures its time complexity. It involves generating random numbers or reading from a file, sorting them, and recording the time taken for various values of n greater than 5000. The results are to be plotted on a graph showing time taken versus n.

Uploaded by

apoorvanayak07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Program 9 Seletion Sort

The document outlines an experiment to design and implement a C program that sorts a set of integers using the Selection Sort method and measures its time complexity. It involves generating random numbers or reading from a file, sorting them, and recording the time taken for various values of n greater than 5000. The results are to be plotted on a graph showing time taken versus n.

Uploaded by

apoorvanayak07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment No 9

Design and implement C program to sort a given set of n integer elements using Selection
Sort method and compute its time complexity.Run the program for varied values of n>5000
and record the time taken to sort .Plot a graph of the time taken versus n.The elements can
be read from a file or can be generated using random number generator.
#include<stdio.h>

#include<time.h>

#include<stdlib.h>

void SelectionSort(int array[ ],int n)

int i,j;

for ( i = 0; i < n; i++)

int min = i;

for ( j = i + 1; j <n; j++)

if (array[j] < array[min])

min = j;

int temp = array[min];

array[min] = array[i];

array[i] = temp;

int main()

int n, a[50000],k;

clock_t st,et;

double ts;
printf("\n Enter How many Numbers: ");

scanf("%d", &n);

printf("\nThe Random Numbers are:\n");

for(k=0; k<n; k++) {

a[k]=rand();

printf("%d\t",a[k]);

st=clock();

SelectionSort(a,n);

et=clock();

ts=(double)(et-st)/CLOCKS_PER_SEC;

printf("\nSorted Numbers are: \n ");

for(k=0; k<n; k++)

printf("%d\t", a[k]);

printf("\nThe time taken is %e",ts);

You might also like