Code For Alls..!

get the code!!

Showing posts with label sorting. Show all posts
Showing posts with label sorting. Show all posts

Wednesday, 19 July 2017

Merge sort is a sorting technique based on divide and conquer technique. With worst-case time complexity being Ο(n log n), it is one of the most respected algorithms. Merge sort first divides the array into equal halves and then combines them in a sorted manner. To understand merge sort, we take an unsorted array as the following − We know that...
Quick sort is a highly efficient sorting algorithm and is based on partitioning of array of data into smaller arrays. A large array is partitioned into two arrays one of which holds values smaller than the specified value, say pivot, based on which the partition is made and another array holds values greater than the pivot value. Quick sort partitions...
Selection sort is a simple sorting algorithm. This sorting algorithm is an in-place comparison-based algorithm in which the list is divided into two parts, the sorted part at the left end and the unsorted part at the right end. Initially, the sorted part is empty and the unsorted part is the entire list. The smallest element is selected from the...
The array is searched sequentially and unsorted items are moved and inserted into the sorted sub-list (in the same array). This algorithm is not suitable for large data sets as its average and worst case complexity are of Ο(n2), where n is the number of items. We take an unsorted array for our example. Insertion sort compares the first...
We take an unsorted array for our example. Bubble sort takes Ο(n2) time so we're keeping it short and precise. Bubble sort starts with very first two elements, comparing them to check which one is greater. C code: #include <stdio.h> #include <stdlib.h> void bub(int *a,int n) { int i,j,val=0,t; for(i=0;i<n;i++) { val=0; for(j=0;j<n-i-1;j++) if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; val=1; } if(val==0) break; } } int...