Skip to main content

Posts

Showing posts from March, 2022

Selection Sort

Selection Sort     Selection sort algorithm sorts an array by reapetly finding  the minimum element (considering ascending order) from unsorted port and putting it at the beginning. Complexity of Selection Sort: Time Complexity Best Case: O(n2) Worst Case: O(n2) Space Complexity Worst Case: O(1) Advantages of Selection Sort Selction sort algorithm easy to implement. No additional data-structure is required. It is in-place sorting method & stable method. The number of swap reduced.O(n) swap  in all cases. Disadvantages of Selction Sort Best & Worst case efficiency is O(n2). CODE 👇 #include <stdio.h> int comp_cnt=0; int main() { int a[20], n , i; printf("\t>>Selection Sort<<\n"); printf("How many numbers you want in array ?\t"); scanf("%d",&n); printf("\nEnter %d element:",n); accept(a,n); selection_sort(a,n); printf("\t>>Sorted Array<<\n"); display(a,n); printf("\nTotal