Question

Python selection sort Consider the following array Give the sequence of the elements in the array...

Python selection sort

Consider the following array Give the sequence of the elements in the array after the Third pass of selection sort. (Ignoring the initial array, the following array)

[29, 72, 98, 13, 87, 66, 52, 51, 36]

Homework Answers

Answer #1

Selection Sort algorithm sorts an array by repeatedly finding the minimum element in the unsorted array and putting it at the beginning. It will first find the smallest element in the array and swap it with the element in the first position, then it will find the second smallest element and swap it with the element in the second position, and it will keep on doing this until the entire array is sorted.

Given array A of size 9 is:

A= [29,72,98,13,87,66,52,51,36]

1. In the first pass, it'll look for minimum element in A[0...8]. Minimum element is 13 which is present at position A[3]. So, it will be placed at the beginning i.e. A[0] and element at A[0] will be swapped with A[3].

So , array after pass 1 will be:

A = [13,72,98,29,87,66,52,51,36]

2. In the second pass it'll look for minimum element in A[1...8]. Minimum element is 29 which is present at position A[3]. So, it'll be placed at A[1] and element at A[1] will be swapped with A[3].

So, array after pass 2 will be:

A = [13,29,98,72,87,66,52,51,36]

3. In the third pass, it'll look for minimum element in A[2...8]. Minimum element is 36 which is present at position A[8]. So it'll be placed at A[2] and element at A[2] will be swapped with A[8].

So, array after pass 3 will be:

A = [13,29,36,72,87,66,52,51,98]

Know the answer?
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
Similar Questions
The bubble sort algorithm discussed in class is used to sort the following sequence of integers:...
The bubble sort algorithm discussed in class is used to sort the following sequence of integers: 47 29 1 9 5 23 • How many passes must the algorithm perform to guarantee the entire sequence is sorted? • What is the list obtained after the first pass? • What is the list obtained after the third pass? • What is the list obtained after the final pass?
This program is in C++, And please consider " sort pass #" for the output: Write...
This program is in C++, And please consider " sort pass #" for the output: Write a program that uses two identical arrays of eight integers. It should display the contents of the first array, then call a function to sort it using an ascending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using...
Consider the following sequence 36​, 45​, 55​, 66​, 78​, 91​, 105​,... ​(a) List the next two...
Consider the following sequence 36​, 45​, 55​, 66​, 78​, 91​, 105​,... ​(a) List the next two terms of the sequence. ​(b) Assuming the sequence is denoted by A1, A2, A3,​..., give an explicit formula for AN. ​(c) Assuming the sequence is denoted by P0, P1, P2,​..., give an explicit formula for PN.
Student Grades Student Test Grade 1 76 62 2 84 90 3 79 68 4 88...
Student Grades Student Test Grade 1 76 62 2 84 90 3 79 68 4 88 84 5 76 58 6 66 79 7 75 73 8 94 93 9 66 65 10 92 86 11 80 53 12 87 83 13 86 49 14 63 72 15 92 87 16 75 89 17 69 81 18 92 94 19 79 78 20 60 71 21 68 84 22 71 74 23 61 74 24 68 54 25 76 97...
Consider the below vector x, which you can copy and paste directly into Matlab. The vector...
Consider the below vector x, which you can copy and paste directly into Matlab. The vector contains the final grades for each student in a large linear algebra course. x = [61 52 63 58 66 92 64 55 76 60 70 78 76 73 45 63 97 70 100 76 50 64 42 100 67 81 81 59 68 62 72 99 66 76 81 59 47 84 67 75 63 86 73 44 51 69 48 74 61...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
have a java application need to create an application which is able to do some analysis...
have a java application need to create an application which is able to do some analysis on temperature data stored in a data file. You will be given the “temperatures.dat” data file which contains the data you must analyze. The analysis you’ll need to do is: Total number of data points Find coldest temperature Find warmest temperature Find average temperature Find the frequency of each temperature Find the most frequent temperature Find the least frequent temperature All classes must be...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an executable with gcc -Wall -DUNIT_TESTS=1 array-utils5A.c The definitions for is_reverse_sorted and all_different are both defective. Rewrite the definitions so that they are correct. The definition for is_alternating is missing. Write a correct definition for that function, and add unit tests for it, using the unit tests for is_reverse_sorted and all_different as models. Please explain the logic errors present in in the definition of is_reverse_sorted...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a text file data_in.txt with the following information (highlight the piece of text below with numbers and copy it to a text file): 54, 70, 75, 63, 17, 59, 87, 16, 93, 81, 60, 67, 90, 53, 88, 9, 61, 8, 96, 98, 12, 34, 66, 76, 38, 55, 58, 27, 92, 45, 41, 4, 20, 22, 69, 77, 86, 35, 19, 32, 49, 15,...
Consider a society with 4 members: Justin, Andrew, Jagmeet and Elizabeth. The following table outlines the...
Consider a society with 4 members: Justin, Andrew, Jagmeet and Elizabeth. The following table outlines the levels of total utility received from each dollar of income for each members of the society. Income Justin Andrew Jagmeet Elizabeth $1 15 32 20 16 $2 29 61 38 30 $3 42 87 54 42 $4 54 110 68 52 $5 65 130 80 60 $6 75 147 90 66 $7 84 161 98 70 $8 92 172 103 72 Assume that the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT