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
Your boss asks you to transmit a small file that includes sensitive personnel data to a server on the network. The server is run
mel-nik [20]

Answer:

a. Telnet transmissions are not encrypted.

Explanation:

Indeed, since <em>Telnet transmissions are not encrypted,</em> all the information sent, and even the characters typed in the telnet console are sent in clear text.

This is a security issue, since any other device in the same network will receive a copy of the information (packets) sent. For default, all the devices, except for the server expecting to receive the information, will discard the packets. However it is easy to actively <em>listen </em>and keep those packets, wich will contain the information in plain text and human readable.

4 0
3 years ago
Which is a network of devices built around a person, typically within 10 meters of range?
11111nata11111 [884]

Answer:

A LAN

Explanation:

A LAN, or a Local Area Network, is a network of devices typically within 10 meters of range regardless of what it is built around.

6 0
3 years ago
An EAP is an:
Oksana_A [137]

i believe the answer would be B

8 0
3 years ago
Read 2 more answers
True or false for a given set of input values, a nand
Katen [24]
Nand stands for "not and". The truth table for a nand is:

a b | a nand b
0 0 |      1
0 1 |      1
1 0 |      1
1 1 |      0

Hopefully this helps you answer your question.
6 0
3 years ago
Explain how electric power and electrical energy are related
AlladinOne [14]

Electric power and electrical energy are related because electrical energy comes from electrical power. If one comes from the other, they are related. Hope this helps!

3 0
2 years ago
Read 2 more answers
Other questions:
  • An engine's _______ contains the cylinder block, the cylinders, the piston, the connecting rods, and the crankshaft assemblies.
    9·2 answers
  • What is the output of the following code snippet? double income = 45000; double cutoff = 55000; double minIncome = 30000; if (mi
    14·1 answer
  • What type of device does a computer turn to first when attempting to make contact with a host with a known IP address on another
    9·2 answers
  • ______ is data that is entered into a computer. ______ is the result produced by a computer.
    6·1 answer
  • Assume that strikeCounter has already been declared to be a "pointer to int". Assume further that strikeCounter has been initial
    5·1 answer
  • How to delete the last element in array
    15·1 answer
  • That's my email address​
    14·1 answer
  • Write a function called min that returns the minimum of the two numbers passed in as parameters.
    13·1 answer
  • PLEASE HELPPPPPPP What should you always disconnect before installing hardware inside a computer’s case?
    6·1 answer
  • Compare mini and mainframe computer in terms of speed,memory and storage​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!