Question

In: Computer Science

Show full work: Please make sure to start the comparison with -infinity and NO NOT COUNT...

  1. Show full work: Please make sure to start the comparison with -infinity and NO NOT COUNT SWAPS!
  2. Sort the list A[ ]={ 20, 13,4, 34, 5, 15, 90, 100, 75, 102, 112, 1} using Insertion Sort and determine the total number of comparisons made (do not count swaps)

Solutions

Expert Solution

Answer:

Step 1:

Given array:

20 13 4 34 5 15 90 100 75 102 112 1
0 1 2 3 4 5 6 7 8 9 10 11

Step 2:

Leftmost are always sorted. We begin with the record in position 0 in the sorted portion, and we will be moving the record in position 1 to the left until it is sorted.

Processing record in position 1. Move the processing record to the left until it reaches the correct position.

Compare 20 and 13, as 13<20 so swap the values.

13 20 4 34 5 15 90 100 75 102 112 1

Step 3:

Processing record in position 2. Move the processing record to the left until it reaches the correct position.

4<20 swap the values.

13 4 20 34 5 15 90 100 75 102 112 1

4<13 swap the values.

4 13 20 34 5 15 90 100 75 102 112 1

Step 4:

Processing record in position 3. Move the processing record to the left until it reaches the correct position. 34 is at their correct place as 34>20.

Step 5:

Processing record in position 4. Move the processing record to the left until it reaches the correct position.

5<34, swap the values.

4 13 20 5 34 15 90 100 75 102 112 1

5<20, swap the values.

4 13 5 20 34 15 90 100 75 102 112 1

5<13, swap the values.

4 5 13 20 34 15 90 100 75 102 112 1

Step 6:

Processing record in position 5. Move the processing record to the left until it reaches the correct position.

15<34, swap the values.

4 5 13 20 15 34 90 100 75 102 112 1

15<20, swap the values.

4 5 13 15 20 34 90 100 75 102 112 1

Step 7:

Processing record in position 6. Move the processing record to the left until it reaches the correct position. 90 is at correct position as 90>34.

Step 8:

Processing record in position 7. Move the processing record to the left until it reaches the correct position. 100 is at correct position as 100>90.

Step 9:

Processing record in position 8. Move the processing record to the left until it reaches the correct position.

75<100, swap the values.

4 5 13 15 20 34 90 75 100 102 112 1

75<90, swap the values.

4 5 13 15 20 34 75 90 100 102 112 1

Step 10:

Processing record in position 9. Move the processing record to the left until it reaches the correct position. 102 is at correct position as 102>100.

Step 11:

Processing record in position 10. Move the processing record to the left until it reaches the correct position. 112 is at correct position as 112>102.

Step 12:

Processing record in position 11. Move the processing record to the left until it reaches the correct position.

1<112, swap the values.

4 5 13 15 20 34 75 90 100 102 1 112

1<102, swap the values.

4 5 13 15 20 34 75 90 ​​​​​​​100 1 102 112

1<100, swap the values.

4 5 13 15 20 34 75 90 ​​​​​​​1 100 102 112

1<90, swap the values.

4 5 13 15 20 34 75 1 90 100 102 112

1<75, swap the values.

4 5 13 15 20 34 1 75 ​​​​​​​90 100 102 112

1<34, swap the values.

4 5 13 15 20 1 34 75 ​​​​​​​90 100 102 112

1<20, swap the values.

4 5 13 15 1 20 ​​​​​​​34 75 ​​​​​​​90 100 102 112

1<15, swap the values.

4 5 13 1 15 ​​​​​​​20 ​​​​​​​34 75 ​​​​​​​90 100 102 112

1<13, swap the values.

4 5 1 13 15 ​​​​​​​20 ​​​​​​​34 75 ​​​​​​​90 100 102 112

1<5, swap the values.

4 1 5 13 15 ​​​​​​​20 ​​​​​​​34 75 ​​​​​​​90 100 102 112

1<4, swap the values.

1 4 5 13 15 ​​​​​​​20 ​​​​​​​34 75 ​​​​​​​90 100 102 112

Step 13:

Finally list is sorted.

Total comparisons made: 26

Please give thumbsup, or do comment in case of any query. Thanks.


Related Solutions

Make sure to scroll left and right to see full question and please show work. Waterway...
Make sure to scroll left and right to see full question and please show work. Waterway makes two products, Simple and Complex. As their names suggest, Simple is the more basic product, and Complex comes with all the bells and whistles. The company has always allocated overhead costs to products based on machine hours. Last year, the company implemented an activity-based costing system, and managers determined the following activity pools and rates based on total overhead of $1,592,000: Rate Assembly...
THIS IS EXAM REVIEW, so please make sure to show the work and make sure the...
THIS IS EXAM REVIEW, so please make sure to show the work and make sure the work is correct. In all tests of hypothesis use the 5% level of significance unless told otherwise. In all confidence interval problems use 95% confidence unless told otherwise. SHOW YOUR WORK. 2. Test scores for a mathematics course have a normal distribution with a mean of 76 and a standard deviation of 12. a.What proportion of scores will be between 70 and 90? b....
Please make sure to complete all parts of the question and to show all work used...
Please make sure to complete all parts of the question and to show all work used to compute the answer so I can see how the answer was found. A five-year annuity of 10 $5,230 semiannual payments will begin nine years from now, with the first payment coming nine and a half years from now. If the discount rate is 10 percent compounded monthly, what is the value of this annuity five years from now? What is the value three...
Make sure to show all steps to receive full credit, that is: a) Identify the claim:...
Make sure to show all steps to receive full credit, that is: a) Identify the claim: state the null and alternative hypotheses. b) Determine the test: left-tailed, right-tailed, or two-tailed. c) Graph your bell-shaped curve and label your levels of significance or critical value. d) Find your standardized test statistic ? and label it on your graph. e) Decide whether to reject or fail to reject the null hypothesis. f) Interpret your result. 1) A medical researcher suspects that the...
Please answer the following questions and show all work and make sure I can read your...
Please answer the following questions and show all work and make sure I can read your writing please. 1) Ethan went on a 10 day fishing trip. The number of small mouth bass caught and released by Ethan each day was as follows. Day 1 2 3 4 5 6 7 8 9 10 # of Fish 9 24 8 9 5 8 9 10 8 10 A. Find the mean, median, and mode B. Find the range, variance, and...
( PLEASE SHOW ALL YOUR WORK). I MPORTANT NOTE: Make sure you do the following: -State...
( PLEASE SHOW ALL YOUR WORK). I MPORTANT NOTE: Make sure you do the following: -State Ho and Ha using notation for each hypothesis test conducted. -Use α= 0.05 for all hypothesis tests conducted. -Explain all results obtained for both hypothesis tests and confidence intervals. You will need your ticker code (company abbreviation) for stock prices for this question. Use your ticker code to obtain the closing prices for the following two time periods to obtain two data sets: March...
Show all your work. Make sure every number has a unit and you show the equations...
Show all your work. Make sure every number has a unit and you show the equations in the variable form before plugging in values. The rod is 2 m long and has a mass of 2 kg. The axis is at the left end. A 13 N force is applied perpendicularly to the axis, a 10 N force is applied at a 60-degree angle in the middle of the rod, a 20 N force is applied at the other end...
6. Calculate the following, and make sure to show your work, including units and substance on...
6. Calculate the following, and make sure to show your work, including units and substance on every numerical value:               a. What is the molarity of a solution that is made of 2.768 g of Pb(NO3)2 in 150 mL of H2O?               b. How many grams of calcium chloride would it take to make 2.7L of a .10M solution? c. What is the concentration of a solution made by diluting 100 mL of 3.0 M HCl with 300 mL water?...
Please show all steps and write neatly. Make sure the proving is with letters and not...
Please show all steps and write neatly. Make sure the proving is with letters and not with numbers. Please!!!! Thank you Let A, B, C be 3 x 3 matrices. Show (AB)C= A(BC)
Please show steps in the calculation. Please make sure you include checking conditions for using the...
Please show steps in the calculation. Please make sure you include checking conditions for using the CLT. Only Answer Question 3 and 4 The Human Resources (HR) Department of a certain college has asked all employees who were employed in 2018 to fill out a survey in December 2018. Three items on the survey were: “Your dental expense in 2018”, “Are you in a family with at least three other family members?”, and “Your medical expenses in 2018”. The manager...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT