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
Jim has just purchased two new SCSI hard disk drives and a controller card for them. He properly installs the hardware in his ma
yawa3891 [41]

Answer:

  • Create partitions on each hard disk drives.
  • Mount the partition created on each hard drive so they are accessible by the the operating system.
  • Format the partitions created with a filesystem recognized by Linux.

Explanation:

Having purchased the two new SCSI hard disk drives with the controller cards for each and installed them properly, before using them for data storage and retrieval he must first use the fdisk command to create one or more partitions on each of the hard disk drives then mount any partitions created on the two hard drives so that they are accessible by the operating system before then proceeding to format any partitions created with a valid filesystem recognized by Linux.

4 0
3 years ago
The name of a person their address and their contact information like phone number and email address or consider the minimum inf
kozerog [31]

The name of a person their address and their contact information like phone number and email address or consider the minimum information or a desktop publishing should include on a letterhead or personal use is true.

True

<u>Explanation:</u>

Since it is used as personal letterhead, end user should have contact details as minimum, which should carry name, phone number and email address.

Letter head should have more space for end user to type or draft the text. If letter head occupies more space end user has limited to space for typing text or draft a letter.

Mostly letter head should simple which should carry less space for letter head. On letter head normally use one color or simple color and it should more attractive.

5 0
3 years ago
Define a class named Doctor whose objects are records for a clinic’s doctors. Derive this class from the class Person given in L
pashok25 [27]

Answer:

Following is defined the required class having accessor methods and test program:

Explanation:

class Person

{

private String doc_name;

public Person(String doc_name)

{

this.doc_name = doc_name;

}

public String getDoc_Name()

{

return doc_name;

}

}

class Doctor extends Person

{

private double office_visit_fee;

private String Specialty;

public Doctor(String doc_name,double office_visit_fee,String Specialty)

{

super(doc_name);

this.office_visit_fee = office_visit_fee;

this.Specialty = Specialty;

}

//accessor methods

public double getOffice_Visit_Fee()

{

return office_visit_fee;

}

public String getSpecialty()

{

return Specialty;

}

public String toString()

{

return "Doctor Name "+getDoc_Name()+" Office Visit Fee :$"+office_visit_fee+

" Specialty : "+Specialty;

}

}

class Test

{

public static void main (String[] args)

{

 Doctor dctr = new Doctor("Joseph Lister",134.56,"Obstetrician");

 System.out.println(dctr);

}

}

Output:

Doctor Name Joseph Lister Office Visit Fee :$134.56 Speciality : Obstetrician

6 0
3 years ago
To add or remove space before or after a paragraph, users should select.
anzhelika [568]

To add or remove space before or after a paragraph, users should select the Line and Paragraph Spacing icon.

6 0
3 years ago
Read 2 more answers
If a system's instruction set consists of an 8-bit opcode, what is the maximum number of output signal lines required for the co
otez555 [7]

Answer:

D. 256

Explanation:

Given

Instructions = 8\ bit

Required

Determine the maximum number of output

To get the required value, we make use of the following:

Maximum = 2^n

Where n is the bits of the opcode.

i.e.

n = 8

Substitute 8 for n in Maximum = 2^n

Maximum = 2^8

Maximum = 256

<em>Hence, option D answers the question</em>

6 0
3 years ago
Other questions:
  • John wants to access specific programs from the Start menu in his laptop. However, he is unable to view them when he clicks the
    14·2 answers
  • How can a Word user insert a page break into a document to isolate a table on a new page?
    13·2 answers
  • Which of the following is the most common tool that Windows administrators use on the domain controller?
    9·1 answer
  • U.S. cybersecurity experts and government officials are increasingly concerned about breaches from __________ into corporate net
    15·1 answer
  • Design and implement an application that uses dialog boxes to obtain two integer values (one dialog box for each value) and disp
    12·1 answer
  • 1) All of this information is part of a ________ in a database.
    9·2 answers
  • A restaurant recorded the ages of customers on two separate days. You are going to write a program to find the minimum age of a
    5·2 answers
  • *
    6·2 answers
  • Which 4 elements are commonly contained in a master page?
    11·1 answer
  • An algorithm is a step by step process that describes how to solve a problem and/or complete a task, which will always give the
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!