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
Calculate the total resistance of this simple circuit. If R1 = 100Ω, R2 = 200Ω.
andreyandreev [35.5K]

Answer: (66.7_1.8)Ω

Explanation: Hope it's helpful

3 0
2 years ago
To what health hazard are people working in offices most likely to be exposed.
Andrei [34K]

Answer:

Sickness

Explanation:

6 0
4 years ago
In cell C15, enter a formula using an IF function to determine if you need a loan. Your available cash is located on the Data sh
san4es73 [151]

The IF function allows the user to make logical comparison among values.

The formula to enter in cell 15 is:  

\mathbf{=IF(\$A\$4 > \$A\$3, "yes", "no")}

In Excel, the syntax of an IF function is:

\mathbf{ = IF ( logical_test , [value_if_true] , [value_if_false] ) }

The representation in the above formula is as follows:

  • logical_test  <em>are the values to be compared</em>
  • [value_if_true] <em>is the return value if the condition is true</em>
  • [value_if_false] <em>is the return value if the condition is false</em>

The cells to compare are given as:  Cell A3 and Cell A4

Where cell A4 contains the car price

So, the IF function is:

\mathbf{=IF(A4 > A3, "yes", "no")}

First, the formula checks if the value of A4 is exceeds A3.

  • If true, the function returns "yes"
  • Else, it returns "no"

To make use of the absolute cell referencing., we simply include the dollar sign between the cell names

Hence, the required formula is:

\mathbf{=IF(\$A\$4 > \$A\$3, "yes", "no")}

Read more about IF functions at:

brainly.com/question/16026173

7 0
3 years ago
Why would a server 2008 r2 dns server have a different security baseline than a windows xp client?
AnnZ [28]
The Answer is <span>If systems perform different functions, security settings can restrict one function but not the other. Also, XP is a desktop OS vs. Server 2008R2 is a Server OS. An XP client can never be a DNS server.

These questions are ambiguous and silly.</span>
3 0
3 years ago
3.12 LAB: Output range with increment of 5 Write a program whose input is two integers, and whose output is the first integer an
Zinaida [17]

The INPUT code of the given programme in Java would be as given below:

In this first we are taking input of two integers j and k from the user and then performing the required operations over it

import java.util.

Scanner;  public class LabProgram {    

public static void main(String[ ] args) {  

Scanner scnr = new Scanner(System.in);        

 int i,j;        

 i  = scnr.nextInt();        

 j = scnr.nextInt();        

if(i<=j) {            

int k = i;            

while (k <= j) {                

System.out.print(k + " ");                

 k = k + 5;            

 }            

 System.out.println();        

 }        

 else{            

 System.out.println("Second integer can't be less than first.");                  

}    

}

}  

Learn more about Java Programming here:

brainly.com/question/18554491

#SPJ10

8 0
2 years ago
Other questions:
  • In linux, a(n) ____ is a data structure that stores all information (such as file permissions, ownership, and file type) about a
    11·1 answer
  • What operating system allows various teams in its office to network and collaborate on projects
    5·1 answer
  • What is the value of the variable phones after the execution of the following code? phones = {'John': '5555555', 'Julie' : '7777
    6·1 answer
  • Stella likes to work with colors and moving pictures. She is good at drawing. Which job role should she choose
    11·2 answers
  • If you have machines doing jobs, fewer staff are needed, therefore costs are
    5·2 answers
  • Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and ca
    7·1 answer
  • "A user reports that the corporate web server cannot be accessed. A technician verifies that the web server can be accessed by i
    8·1 answer
  • In black and white,<br><br> we must be more conscious of image
    11·1 answer
  • In two to three sentences, describe one advanced search strategy and how it is useful.
    13·1 answer
  • What was used to enhance silent films of the early 1900s
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!