This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: Implementation of selection sort algorithm in java with Example program
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Selection sort algorithm is to arrange unsorted elements in to sorting order with increasing or decreasing order.
To sort list of unsorted list of elements first it will search for minimum value in the list and place it in first index.
Now first place is fixed with smallest value in the list now it starts from second element and compare next element and if it is big it compares next element if it is small it picks that element and compares with next element.
So again it picks smallest element in the list and place it in second place. This procedure will repeat until it reaches n-1 position.
Time complexity of selection sort algorithm:
1. Best case time complexity: O(n2) 2.Average case time complexity: O (n2) 3.Worst case time complexity: O (n2)
Program #1: Write a Java example program to sort unsorted elements in ascending order using selection sort algorithm
package com.java.sortingalgorithms;
public class SelectionSortInJava {
public static int[] selectionSortArray(int[] array){