Skip to content
DATA STRUCTURE
DATA STRUCTURE

Learn everything about Data structures.

  • Algorithms
  • DSA
  • Array
  • Stack
  • Queue
  • Matrix
  • Programs
DATA STRUCTURE

Learn everything about Data structures.

Selection Sorting Algorithm

YASH PAL, November 26, 2022May 28, 2024

Selection Sorting Algorithm: The selection sort starts from the first element and searches the entire list until it finds the minimum value. The sort places the minimum value in the first place, selects the second element, and searches for the second smallest element. The process continues until the complete list is sorted. A selection sort is one in which successive elements are selected in order and placed into their proper sorted positions.

[br]

The selection process must be done only from 1 to n – 1 rather than up to n. Analysis of the selection is so straightforward. The first pass makes n – 1 comparison, the second pass makes n – 2, and so on Such total comparisons are (N – 1) + (N2) (NE -3) ++ 2 + 1 = N (N – 1) / 2 = 0 (N³) The little additional storage required (except to hold few temporary variables.). The sort may therefore be categorized as O (N³), although it is faster than the bubble sort there is no improvement if the input file is completely sorted or unsorted.

[br]

Despite the fact that it is simple to code, it is unlikely that the straight selection sort would be used on any files but those for which n is small. The selection sort algorithm for sorting works as follows. First, find the smallest element in the list and put it in the first position. Then find the second smaller element in the list and put it in the second position. It is to be noted that the number of comparisons in the selection sort algorithm is independent of the original sort of the elements. The selection sort method requires (n – 1) passes to sort an array.

[br]

selection sorting algorithm

[br]

Selection Sorting Algorithm

SELECTION SORT (A, N)
Here A is an array with N elements. This algorithm sorts the array A with N elements in ascending order.

1. Repeat Steps 2 to 5 for I = 1 to N – 1:
2.       Set MIN : = A [ U ]
3.       Set POS : = I.
4.       Repeat Steps for J = 1 + 1 to N:
                 If A [ J ] < MIN , then :
                      (a) Set MIN : = A [ J ].
                      (b) Set POS : = J.
                 [ End of If structure. ]
           [ End of Step 4 loop |
           If I != POS, then
                (a) Set TEMP : = A [ I ]
                (b) Set A [ I ] = A [ POS ]
                (c) Set A [ POS ] : = TEMP
           [ End of If structure. ]
     [ End of step 1 loop 1 ]
     Return.

[br]

algorithms data structures selection sorting algorithmDSAselection sorting

Post navigation

Previous post
Next post
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • About US
  • Contact US
  • Data Structures and algorithms tutorials
  • Digital Communication Tutorials
  • DMCA
  • HackerRank All Algorithms problems solutions
  • HackerRank C problems solutions
  • HackerRank C++ problems solutions
  • HackerRank Java solutions
  • HackerRank Python solutions
  • Human Values Tutorials
  • Internet of Things Tutorials
  • Privacy Policy
©2025 DATA STRUCTURE | WordPress Theme by SuperbThemes