Professional Documents
Culture Documents
Introduction:-
Insertion sort works by inserting an element at its suitable place in each iteration.
The array elements are compared with each other sequentially and then arranged
simultaneously in some particular order.
It is less efficient on large lists.
Example:-
Complexity:-
Best case: Θ(n)
Worst Case: Θ (n^2)
Average case: Θ(n^2)
Program:-
#include <stdio.h>
#include <time.h>
int main()
{
int n, i, j, v;
int arr[50];
double time_spent= 0.0;
printf("Please Enter number of elements\n");
scanf("%d", &n);
printf("Please Enter %d integers\n", n);
for (i = 0; i < n; i++)
scanf("%d", &arr[i]);
Output:-