Ask Question
14 October, 08:31

When writing code for in-place operation, what kind of main method would you use in either selection sort or insertion sort algorithms? Oint [] O array O list O void double

+3
Answers (1)
  1. 14 October, 10:03
    0
    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
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “When writing code for in-place operation, what kind of main method would you use in either selection sort or insertion sort algorithms? ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers