Biology, asked by ayushrajrai13, 1 year ago

Please explain me selection sort step by step explanation using java scanner.

Answers

Answered by Anonymous
1

in array we learn two type of sorting

bubbles sort

selection sort

The selection sort is a combination of searching and sorting. During each pass, the unsorted element with the smallest (or largest) value is moved to its proper position in the array.

suppose

1

2

3

4

5

we take max or min value at any position and then compare each and every element(1 to 5) using loop and make it sorted out .

.

Answered by Annesha672
1

Java scanner is most probably used by the users to sort out a given array in ascending or descending order but, in selection sort algorithm, we search for the lowest element and arrange it to the proper location and we also swap the current element element with the next lowest number.

The selection sort algorithm works in a very simple way and maintains to sub-array for the given array:

1) The sub-array is already sorted.

2) The second sub-array is unsorted.

With every irritation the selection sort, an element is picked from the unsorted sub-array. For example:

arr[] = 25 35 45 12 65 10

// Find the minimum element in arr[0.....5]

10 25 35 45 12 65

// Find the minimum element in arr[1.....5] and place it at the beginning of

arr[1.....5]

10 12 25 35 45 65

// Find the minimum element in arr[2....5] and place at the beginning of arr[2....5] (Now, you can't see that the array is already sorted.)

The output is: 10 12 25 35 45 65

Similar questions