Respuesta :

Answer:

Many sorting algorithms rearrange arrays into sorted order such as bubble sort , insertion sort , selection sort.

Explanation:

Insertion Sort

is an algorithm used to sort the array as follow

For example

12, 11, 15, 2, 6

Let us loop for i = 1 (second element of the array) to 4 (last element of the array)

i = 1. Since 11 is smaller than 12, move 12 and insert 11 before 12

11, 12, 15, 2, 6

i = 2. 13 will remain at its position as all elements in A[0..I-1] are smaller than 13

11, 12, 15, 2, 6

i = 3. 2 will move to the beginning and all other elements from 11 to 15 will move one position ahead of their current position.

2, 11, 12, 15, 6

i = 4. 6 will move to position after 5, and elements from 11 to 13 will move one position ahead of their current position.

2, 6, 11, 12, 13

Similarly in selection sort

arr[] = 64 23 12 22 11  70

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

11 23 12 22 64  70

Find the minimum element in arr[1...5]

and place it at beginning of arr[1...5]

11 12 23 22 64  70

Find the minimum element in arr[2...5]

and place it at beginning of arr[2...5]

11 12 23 22 64  70

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

11 12 22 23 64 70

ACCESS MORE