1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
maksim [4K]
3 years ago
10

Selection Sort List the resulting array after each iteration of the outer loop of the selection sort algorithm. Indicate the num

ber of character-to-character comparisons made for each iteration (line 07 of the Selection Sort algorithm at the end of the assignment). Sort the following array of characters (sort into alphabetical order): CQS A XBT Selection Sort 01 public static void selectionSort (int[] a) { 02 03 int n = a.length; for (int i = 0 ; i 0; j--) { if ( a[j-1] > a[j] ) { exchange(a, j-1, j); } else break; 10 } 12 private static void exchange (int[] a, int i, int j) { 13 // exchange the value at index i with the value at index j int temp = a[i]; a[i] = a[j]; a[j] = temp; 17 }
Computers and Technology
1 answer:
Lady bird [3.3K]3 years ago
4 0

Solution :

Initial array = $\text{C,Q,S,A,X,B,T}$

$n= 7$(length of the array)

$\text{1st}$ Iteration:

i = 1

  j = 1

  $\text{a[j-1]}$ = C

  a[j] = Q

  since $\text{a[j-1]}$ < a[j] , break from inner loop

 

Number of comparisons in 1st Iteration = 1

After 1st Iteration:

Array : C,Q,S,A,X,B,T

2nd Iteration:

i = 2

  j = 2

  a[j-1] = Q

  a[j] = S

  since a[j-1] < a[j], break from inner loop

 

Number of comparisons in 2nd Iteration = 1

After 2nd Iteration:

Array : C,Q,S,A,X,B,T

3rd Iteration:

i = 3

  j = 3

  a[j-1] = S

  a[j] = A

  since a[j-1] > a[j], exchange a[2] with a[3]

  Array : C,Q,A,S,X,B,T

 

  j = 2

  a[j-1] = Q

  a[j] = A

  since a[j-1] > a[j], exchange a[1] with a[2]

  Array : C,A,Q,S,X,B,T

 

  j = 1

  a[j-1] = C

  a[j] = A

  since a[j-1] > a[j], exchange a[0] with a[1]

  Array : A,C,Q,S,X,B,T

 

  j = 0, break from inner loop

Number of comparisons in 3rd Iteration = 3

After 3rd Iteration:

Array : A,C,Q,S,X,B,T

4th Iteration:

i = 4

  j = 4

  a[j-1] = S

  a[j] = X

  since a[j-1] < a[j], break from inner loop

 

Number of comparisons in 4th Iteration = 1

After 4th Iteration:

Array : A,C,Q,S,X,B,T

5th Iteration:

i = 5

  j = 5

  a[j-1] = X

  a[j] = B

  since a[j-1] > a[j], exchange a[4] with a[5]

  Array : A,C,Q,S,B,X,T

 

  j = 4

  a[j-1] = S

  a[j] = B

  since a[j-1] > a[j], exchange a[3] with a[4]

  Array : A,C,Q,B,S,X,T

 

  j = 3

  a[j-1] = Q

  a[j] = B

  since a[j-1] > a[j], exchange a[2] with a[3]

  Array : A,C,B,Q,S,X,T

 

  j = 2

  a[j-1] = C

  a[j] = B

  since a[j-1] > a[j], exchange a[1] with a[2]

  Array : A,B,C,Q,S,X,T

 

  j = 1

  a[j-1] = A

  a[j] = B

  since a[j-1] < a[j], break from inner loop

 

Number of comparisons in 5th Iteration = 5

After 5th Iteration:

Array : A,B,C,Q,S,X,T

6th Iteration:

i = 6

  j = 6

  a[j-1] = X

  a[j] = T

  since a[j-1] > a[j], exchange a[5] with a[6]

  Array : A,B,C,Q,S,T,X

 

  j = 5

  a[j-1] = S

  a[j] = T

  since a[j-1] < a[j], break from inner loop

 

Number of comparisons in 6th Iteration = 2

After 6th Iteration:

Array : A,B,C,Q,S,T,X

Sorted Array : A B C Q S T X  

You might be interested in
What is the output of the following code?<br> print (12 // 6)
sveta [45]

Answer:

2

  • See here we have //
  • // means floor division in python.
  • It gives us only the integer part not floating or decimal.

So

12//6=2

8 0
2 years ago
Match the job roles with their appropriate qualifications. business analyst multimedia artist network and computer systems admin
Tanya [424]

Answer:

business analyst:  degree in business administration arrowRight  

multimedia artist : training in 2D and 3D modeling arrowRight​

network and computer systems administrator: master's course in management information systems arrowRight  

software quality assurance engineer: knowledge of the software lifecycle process arrowRight  

Explanation:

Please check the answer section

6 0
3 years ago
Read 2 more answers
Why is it important to think about the programming language to use?
Sloan [31]
In think is C or B in my opinion
6 0
3 years ago
Advantages of a computer​
Bess [88]

Answer:

It eases work.

It is deligent.

It is versatile.

8 0
3 years ago
Which of the statements below is true?
emmainna [20.7K]

The given statement that is true is; B: The Formatting, Standard, and Drawing toolbars are displayed.

<h3>Which statement is true of microsoft word?</h3>

In Microsoft word, there are different toolbars that are useful in operation. Now, from the given image from Microsoft word, we can see that toolbar is clicked. However in the fly-down from it, we see that the standard, formatting and drawing toolbars are ticked and as such they are the ones displayed.

Looking at the options, the correct one is Option B because it tells us that Formatting, Standard, and Drawing toolbars are displayed.

Read more about a true statement at; brainly.com/question/25605883

8 0
2 years ago
Other questions:
  • In programming, what is a floating-point number?<br>​
    7·1 answer
  • List 3 items that were on kens resume that should have been excluded
    13·2 answers
  • Write down the steps that you will take to organize your files
    12·2 answers
  • The user enters a URL into a web browser, the web browser sends the information to the DNS server to look up the IP address, the
    12·1 answer
  • 1000base-t is a standard for achieving throughputs ____ times faster than fast ethernet over copper cable.
    8·1 answer
  • ap csp The local, remote, and upstream _______ can each have multiple ___ _____. When a participant in a collaborative group on
    5·1 answer
  • List the operating system you recommend, and write a sentence explaining why.
    8·1 answer
  • How does the sky change as onegets above Earth’s atmosphere?
    5·1 answer
  • What stipulates that the source code of any software published under its license must be freely available.
    14·1 answer
  • Question 8 of 10
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!