Java Example – Selection Sort Algorithm




Selection Sort Algorithm using Java

Selection Sort

    • Repeatedly searches for the largest value in a section of the data
      • Moves that value into its correct position in a sorted section of the list
    • Uses the Find Largest algorithm

 Pseudo Code

 

  • Count comparisons of largest so far against other values
  • Find Largest, given m values, does m-1 comparisons
  • Selection sort calls Find Largest n times,
    • Each time with a smaller list of values
    • Cost = n-1 + (n-2) + … + 2 + 1 = n(n-1)/2

 Efficiency

  • Time efficiency
    • Comparisons: n(n-1)/2
    • Exchanges: n (swapping largest into place)
    • Overall: (n2), best and worst cases
  • Space efficiency
    • Space for the input sequence, plus a constant number of local variables

 

In this lesson we will learn how to write a source code in Java programming language for doing simple Selection sort using array in ascending order.

Java Example :

 
 





Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com