Algorithm

Merge short Algorithm code in c

#include<stdio.h> int main() {  int i;     int A[5]={4,5,6,7,3};     int p=0;     int r=4;     mergeshort(A,p,r);     for(i=0; i<=r; i++)       printf(“%d “, A[i]);

Time complexity of insertion , bubble & merge short!

Insertion Sort: Average Case / Worst Case : Θ(n2) ; যখন ইনপুট গুলো descending order এ থাকে। Best Case : Θ(n) ; যখন ইনপুট sorted অবস্থায় সাজানো থাকে। Merge Sort : Average

Insertion short c programming code

#include int main() { int i,j,key=0; int a[5]={2,4,3,7,6}; for(j=1;j<5;j++) { key=a[j]; i=j-1; while(i>=0) { if (key<a[i]) { a[i+1]=a[i]; } else{ break; } i–; } a[i+1]=key; } for(i=0;i<5;i++) printf(“%d”,a[i]); }

Bubble short c programming code

#include int main() { int i, j,temp; int a[5]={1,2,2,6,5}; for(i=0;i<5;i++) { for(j=0; j<5-i; j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } for(i=0;i<5;i++) { printf("%d",a[i]); } } }