Professional Documents
Culture Documents
NAME: Biswa Bhusan Gupta ROLL NO: 1805030: Soln 4.1
NAME: Biswa Bhusan Gupta ROLL NO: 1805030: Soln 4.1
NAME: Biswa Bhusan Gupta ROLL NO: 1805030: Soln 4.1
Soln 4.1:
#include <stdio.h>
#include<time.h>
#include<stdlib.h>
// Merges two subarrays of arr[].
// First subarray is arr[l..m] //
Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k; int
n1 = m - l + 1;
int n2 = r - m;
#Tavish Awasthy
#1805622
merge(arr, l, m, r);
}
}
int main()
{ int n;
printf("\nEnter the no. of inputs: ");
scanf("%d",&n); int
arr[n];
srand(time(0));
for(int i=0;i<n;i+
+) arr[i]=rand();
int arr_size = sizeof(arr) / sizeof(arr[0]);
clock_t start=clock();
mergeSort(arr, 0, arr_size - 1);
clock_t end=clock();
double time=(double)(end-start)/CLOCKS_PER_SEC;
printf("Exeution time for %d is %lf\n",n,time);
return 0;
}
GRAPH:
Soln 4.2:
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
// A recursive binary search function. It returns
// location of x in given array arr[l..r] is present,
// otherwise -1
int binarySearch(int arr[], int l, int r, int x)
{
if (r >= l) {
int mid = l + (r - l) / 2;
// If the element is present at the middle
// itself if
(arr[mid] == x)
return mid;
#Tavish Awasthy
#1805622
int arr[r],i;
srand(time(0));
for(i=0;i<r;i++)
arr[i]=rand();
int n = sizeof(arr) / sizeof(arr[0]);
printArray(arr,n);
int x;
return 0;
}
GRAPH:
Soln 4.3:
#include <math.h>
#include <stdio.h>
#include<time.h>
#include<stdlib.h>
/* Function to sort an array using insertion sort*/
void insertionSort(int arr[], int n)
{
int i, key, j; for (i =
1; i < n; i++) { key =
arr[i];
j = i - 1;
clock_t start=clock();
insertionSort(arr, n);
clock_t end=clock();
double time=(double)(end-start)/CLOCKS_PER_SEC;
printf("Exeution time for %d is %lf\n",n,time);
return 0;
}
GRAPH:
#Tavish Awasthy
Soln 4.4:
#1805622
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int temp;
void heapify(int arr[], int size, int i)
{ int largest = i;
int left = 2*i + 1;
int right = 2*i + 2;
}
GRAPH: