GALERIA FOTOGRAFICA

Todas las fotos de familia, amigos y eventos realizados por los grupos al cual pertenesco estan en este segmento...

lunes, 13 de abril de 2020

A Quick Guide To Selection Sorting



In this Article I'll tell you about Selection Sort
Selection sort is that type of sorting in which smallest element of a list is searched and then this number is swapped with the first element of the list and then second smallest element is searched in the list and is swapped with the second element of the list and so on i,e this "thingy" thing continues on till n-1 times (where 'n' is the number of terms).
COMPLEXITY:-
Complexity of Selection sort is O(n^2) in best case as well as in worst case.

Well selection sort is not a good sorting algorithm which you can see even from the complexity of selection sort because selection sort performs same number of comparisons even in the best case as in the worst case. Which makes it very slow.
Pseudo-code:-
sort(Arr)
for i = 0 to n-1
smallest = location of smallest number from Arr[i] to Arr[n-1]
swap Arr[i] with Arr[smallest]

/*C Program: Implementation of Selection Sort*/
#include<stdio.h>
void swap(int a[], int i, int j){
    int tmp = a[i];
    a[i] = a[j];
    a[j] = tmp;
}
void selectionSort(int a[], int l, int h){
   for(int i=l; i<h; i++){
     int small  = i;
     for(int j=i+1; j<=h; j++){
       if(a[j] < a[i]) small = j;
     }
     swap(a,i,small);
   }
}
int main(void) {
   int arr[10], n;
   printf("Enter Size of Array: ");
   scanf("%d", &n);
   printf("Enter %d elements:\n", n);
   for(int i=0; i<n; i++) scanf("%d", &arr[i]);
   selectionSort(arr, 0, n-1);
   printf("Sorted Array is as:\n");
   for(int i=0; i<n; i++) printf("%d ", arr[i]);
   printf("\n");
   return 0;
}
More information
  1. Hacking Tools Windows 10
  2. Hacker
  3. Top Pentest Tools
  4. Pentest Tools Kali Linux
  5. What Are Hacking Tools
  6. Hacker
  7. Pentest Tools Open Source
  8. Pentest Tools Windows
  9. Pentest Automation Tools
  10. Hack Tool Apk No Root
  11. Ethical Hacker Tools
  12. Pentest Tools Website
  13. Hacking Tools
  14. Hacker Security Tools
  15. Hack Tools Pc
  16. Hacking Tools For Kali Linux
  17. Kik Hack Tools
  18. Pentest Tools Download
  19. Hacking Tools For Games
  20. Pentest Tools Bluekeep
  21. Hacking Apps
  22. Hacker Tools Windows
  23. Pentest Tools Tcp Port Scanner
  24. Bluetooth Hacking Tools Kali
  25. Pentest Tools Github
  26. Hack And Tools
  27. Hack Apps
  28. Best Pentesting Tools 2018

0 comentarios:

Blog Archive

  © Blogger templates ProBlogger Template by Ourblogtemplates.com 2008

Back to TOP