Counting sort

Counting Sort :

n is  number of values in array , k is the range of values (max – min )

Compexity : O(n+k)

Counting sort is a sorting technique to sort an array in linear time. It uses an extra space for counting occurrence  of each object in array. This technique is efficient when range of data is not much larger than number of inputs to be sorted.

Kth smallest element in Array

C code to find out Kth smallest element in array .

Approach 1:

Sort the array using any sorting method and return the value of kth index.

Approach 2:

Using partition function of quick sort which return the index of the pivot value.

comparing the returning value from partition function with k.

Bubble sort on array

Algorithm: Bubble Sort

Code:

Quick Sort on Array

Algorithm: Quick Sort on Array
Complexity : Average case O(n logn) , worst Case O(n^2)

Code:

Quick sort on array.

Heap Sort on array

Algorithm : Heap Sort on Array
Complexity :O(n logn)

Heap sort in Array code in C .

insertion sort on array

Algorithm : Insertion Sort on array
Complexity : O(n^2)

Insertion sort on array code in C .

Sort an array in C (Basic Method)

Complexity : O(n2)

Explanation:

Below code picks a cell one by one and compares with each other cells , if value of current cell is greater than other cell then it will swap with other value. Similarly it performs untill picked cell is last cell.

Code :