« Home | Reversing Some C++ Io Operations » | How To Run Online Kali Linux Free And Any Devices » | DirBuster: Brute Force Web Directories » | Wireless Scenarios Part 1: EAP-Radius JTR Hashcat,... » | DEFINATION OF HACKING » | How Do I Get Started With Bug Bounty ? » | How To Remove Write Protection From USB Drives And... » | inBINcible Writeup - Golang Binary Reversing » | DSploit » | Networking | Routing And Switching | Tutorial 2 | ... »

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 articles
  1. Hacker Tools Free Download
  2. Pentest Tools Free
  3. Hacking Tools Windows 10
  4. Hacker Techniques Tools And Incident Handling
  5. Usb Pentest Tools
  6. Hacker Tools Free Download
  7. Hacker Tools List
  8. Pentest Tools Port Scanner
  9. Hacking Tools Github
  10. How To Hack
  11. Pentest Tools Apk
  12. Nsa Hack Tools
  13. Computer Hacker
  14. Hacker Tools Mac
  15. Hacking Tools Windows 10
  16. Hacking Tools Windows
  17. Hacker Tools
  18. Hacking Tools Usb
  19. Hack Tools For Pc
  20. Hacker Tools For Windows
  21. Hacking Tools For Windows
  22. Pentest Tools Github
  23. Hacking Tools Name
  24. What Are Hacking Tools
  25. Hacking Tools Kit
  26. Hacker Tools Online
  27. Pentest Recon Tools
  28. Hacking Tools For Beginners
  29. Install Pentest Tools Ubuntu