Question

Show the execution of the selection sort algorithm on the following array. Hint: The yellow or...

Show the execution of the selection sort algorithm on the following array. Hint: The yellow or shaded squares should be the remaining unsorted values.

Pass #

0

1

2

3

4

5

6

7

0

16

11

21

32

41

20

3

9

1

2

3

4

5

6

7

Show the execution of the insertion sort algorithm on the following array. Hint: The yellow or shaded squares should be the remaining unsorted values.

Pass #

0

1

2

3

4

5

6

7

0

16

11

21

32

41

20

3

9

1

2

3

4

5

6

7

Show the execution of the bubble sort algorithm on the following array. Hint: The yellow or shaded squares should be the remaining unsorted values.

Pass #

0

1

2

3

4

5

6

7

0

16

11

21

32

41

20

3

9

1

2

3

4

5

6

7

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

Selection sort:

The selection sort algorithm while execution contains two subarrays from which one of the arrays is in sorted order and another one is in unsorted order.

The sorted order contains the element from the unsorted array in order of minimum to maximum.

so the smallest to largest numbers will be placed and sorted after each pass.

so the steps will be

Pass #

0

1

2

3

4

5

6

7

0

16

11

21

32

41

20

3

9

1

3 11 21 32 41 20 16 9

2

3 9 21 32 41 20 16 11

3

3 9 11 32 41 20 16 21

4

3 9 11 16 41 20 32 21

5

3 9 11 16 20 41 32 21

6

3 9 11 16 20 21 32 41

7

3 9 11 16 20 21 32 41

Now the array is sorted.

Insertion sort:

Insertion sort start to sort the subarray at each pass and the sorted array grows until all the elements are sorted

Pass #

0

1

2

3

4

5

6

7

0

16

11

21

32

41

20

3

9

1

11 16 21 32 41 20 3 9

2

11 16 21 32 41 20 3 9

3

11 16 21 32 41 20 3 9

4

11 16 21 32 41 20 3 9

5

11 16 20 21 32 41 3 9

6

3 11 16 20 21 32 41 9

7

3 9 11 16 20 21 32 41

Bubble sort:

Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order.

This way the largest element will be placed at the end of the array at each pass.

Pass #

0

1

2

3

4

5

6

7

0

16

11

21

32

41

20

3

9

1

11 16 21 32 20 3 9 41

2

11 16 21 20 3 9 32 41

3

11 16 20 3 9 21 32 41

4

11 16 3 9 20 21 32 41

5

11 3 9 16 20 21 32 41

6

3 9 11 16 20 21 32 41

7

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Add a comment
Know the answer?
Add Answer to:
Show the execution of the selection sort algorithm on the following array. Hint: The yellow or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Selection Sort is a common algorithm to sort the elements of an array. First, it scans...

    Selection Sort is a common algorithm to sort the elements of an array. First, it scans the elements of the array to find the smallest value and places it at index 0, thus creating a sorted “subarray” of size 1 that contains the smallest value. Then it scans the remaining unsorted values for the new smallest value and places it at index 1, creating a sorted subarray of size 2 that contains the 2 smallest values. It continues in this...

  • Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8...

    Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...

  • Q3) Apply Quick sort algorithm to sort the following Array (Show complete steps, and show the...

    Q3) Apply Quick sort algorithm to sort the following Array (Show complete steps, and show the values of p,r and q) 7 13 5 2 4 10 15 6 3 6

  • Implement in C SharpCreate a new algorithm based on the algorithm, selection sort. The new algorithm...

    Implement in C SharpCreate a new algorithm based on the algorithm, selection sort. The new algorithm should be able to sort an array like this: Input: an array that has n elements, and the values of its elements are assigned randomly, for example: Index 0 1 2 3 4 5 value 7 3 6 2 1 5 Output: an array - its first n/2 elements are sorted in ascending order and its second n/2 elements sorted in descending order. That...

  • 1.Show the state of the following array after the outer loop of the bubble sort algorithm...

    1.Show the state of the following array after the outer loop of the bubble sort algorithm has executed one time. [0] [1] [2] [3] [4] [5] 19 23 2 4 99 1 2. Show the state of the following array after the outer loop of the selection sort algorithm has executed two times. [0] [1] [2] [3] [4] [5] 12 1 9 23 17 11 3. Show the state of the following array after the outer loop of the insertion...

  • [5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9,...

    [5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9, 4, 3). Assuming we call the following function using statement selection sort (int array, 7); Please fill the table to show the changes of the array int_array after each iteration. The first column is filled. void selection_sort (int list[], int list_size) for (int i = 0; i < list size - 1; 1++) int current min = list[1]; int current_min_index-i for (int j -...

  • //CODE 16-02.cpp //Demonstrates a template function that implements //a generic version of the selection sort algorithm....

    //CODE 16-02.cpp //Demonstrates a template function that implements //a generic version of the selection sort algorithm. #include <iostream> using std::cout; using std::endl; template<class T> void sort(T a[], int numberUsed); //Precondition: numberUsed <= declared size of the array a. //The array elements a[0] through a[numberUsed - 1] have values. //The assignment and < operator work for values of type T. //Postcondition: The values of a[0] through a[numberUsed - 1] have //been rearranged so that a[0] <= a[1] <=... <= a[numberUsed -...

  • After a single pass of selection sort algorithm (a single swap) what would be the state...

    After a single pass of selection sort algorithm (a single swap) what would be the state of the array? [7 ,6 , 12 , 13 , 6 , 17 , 0 , -2 , 31 , 1] After a single pass of bubble sort algorithm (could be zero/one/many swaps), what would be the state of the array? [7 , 6 , 12 , 13 , 6 , 17 , 0 , -2 , 31 , 1]

  • Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers...

    Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. USE THIS STUCTURE struct nodeQ{                            node *front;                            node *rear;               };               nodeQ que[10]; enqueue(que[i],data); EXAMPLE: Original, unsorted list: [170, 45, 75, 90, 2, 802, 24, 66] 1ST PASS:...

  • Question 5 (10 Points) Write a well-documented, Python program, hmwk305.py that implements the Selection-Sort algorithm. Selection-Sort...

    Question 5 (10 Points) Write a well-documented, Python program, hmwk305.py that implements the Selection-Sort algorithm. Selection-Sort segments the list into sorted and unsorted elements. The algorithm continues to remove the smallest element of the unsorted list and adds it to the sorted segment. Implement the algorithm that accepts an unsorted list and returns a sorted one - in ascending order. 5 3 8 Initial List 4 6 18 4 6 Minimum Swaps Position: Sorted List Length 1 Minimum Swaps Position:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT