OBJECTIVE- Write a C program to implement Quick Sort and also plot time complexity. ALGORITHM- -select a pivot either from 1-first element 2-middle element 3-last element and with ech iteration arrange the element such that towards left of it lies all element smaller than pivot element and in it's right all element grater than the pivot then repeat the process quicksort(arr,low,p-1) quicksort(arr,p+1,high) #include<stdio.h> #include<stdlib.h> #include<time.h> #include<string.h> void quicksort(int *arr,int low,int high) { int n,pivot,i=low,j=high; if(low<high) { pivot=low; while(i<j) { while(arr[i...
Posts
OBJECTIVE- Write a program to implement Merge sort and also draw it's plot. ALGORITHM- MergeSort(arr[], l, r) If r > l 1. Find the middle point to divide the array into two halves: middle m = (l+r)/2 2. Call mergeSort for first half: mergeSort(arr, l, m) 3. Call mergeSort for second half: mergeSort(arr, m+1, r) 4. Merge the two halves sorted in step 2 and 3: merge(arr, l, m, r) To draw the plot we need to know the execution time for every single input size so for that purpose we are using clock() function here which will give us time after each exe...
OBJECTIVE - Write a C program to Sort the N Names in an Alphabetical Order. ALGORITHM - -Start from the first name and compare it with all other names -if it is lexicographically large from others then swap both of them -Repeat this process for n-1 names CODE- #include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h> void merge(char a[][30],long int l,long int m,long int r) { long int i,j,k; long int n1=m-l+1; long int n2=r-m; char la[n1][30],ra[n2][30]; for(i=0;i<n1;i++) strcpy(la[i],a[l+i]); for(j=0;j<n2;j++) strcpy(ra[j],a[m+1+j]); i=0;j=0;k=l; while(i<n1 && j<n2) { if(strcmp(la[i],ra[j])<0) { ...