Question

In: Computer Science

JAVA Start with the SelectionSort class in the zip file attached to this item. Keep the...

JAVA

Start with the SelectionSort class in the zip file attached to this item. Keep the name SelectionSort, and add a main method to it.

  • Modify the selectionSort method to have two counters, one for the number of comparisons, and one for the number of data swaps. Each time two data elements are compared (regardless of whether the items are in the correct order—we're interested in that a comparison is being done at all), increment the comparison counter. Each time two data items are actually swapped, increment the data swap counter.
  • At the end of the selectionSort method, print the size of the sorted array, and the counters. (Be sure to identify which counter is which in your print message
  • In your main method,
    • Declare a final int, NUM_ELEMENTS. Initially set NUM_ELEMENTS to 10 to debug your program.
    • Declare and create three double arrays of NUM_ELEMENTS length, lo2Hi, hi2Lo, random.
    • Initialize the first array, lo2Hi, with values 1.0, 2.0, …, NUM_ELEMENTS
    • Initialize the second array, hi2Lo with values NUM_ELEMENTS, 24.0,…, 1.0
    • Initialize the third array, random, with random double values between 0.0 and less than 1.0
    • call the selectionSort method using each array. (Note: you might want to print the array elements themselves for debugging purposes when NUM_ELEMENTS is small, but you’ll not want to print them with larger values for NUM_ELEMENTS.)
  • Run your program three times with different values for NUM_ELEMENTS: 1000, 2000 and 4000.

In your submission write some text describing the relationship between the number of comparisons of the various values of NUM_ELEMENTS. For example, what do we find if we divide the number of comparisons for 2000 elements by the number of comparisons for 1000 elements? What do we find if we divide the number of comparisons for 4000 elements by the number of comparisons for 2000 elements?

SELECTION SORT FILE MUST USE THIS IN PROGRAM!!! PLEASE

public class SelectionSort {
/** The method for sorting the numbers */
public static void selectionSort(double[] list) {
for (int i = 0; i < list.length - 1; i++) {
// Find the minimum in the list[i..list.length-1]
double currentMin = list[i];
int currentMinIndex = i;

for (int j = i + 1; j < list.length; j++) {
if (currentMin > list[j]) {
currentMin = list[j];
currentMinIndex = j;
}
}

// Swap list[i] with list[currentMinIndex] if necessary;
if (currentMinIndex != i) {
list[currentMinIndex] = list[i];
list[i] = currentMin;
}
}
}
}

Solutions

Expert Solution

Given below is the code and output. You can comment out the 3 lines to call display() from main() method when testing with 1000 or 2000 elements. Please do rate the answer if it helped. Thank you.

To indent code in eclipse, select code by pressing Ctrl+A and then press Ctrl+i

SelectionSort.java

public class SelectionSort {
/** The method for sorting the numbers */
public static void selectionSort(double[] list) {
long comparisons = 0;
long swaps = 0;
for (int i = 0; i < list.length - 1; i++) {
// Find the minimum in the list[i..list.length-1]
double currentMin = list[i];
int currentMinIndex = i;
for (int j = i + 1; j < list.length; j++) {
comparisons++;
if (currentMin > list[j]) {
currentMin = list[j];
currentMinIndex = j;
}
}
// Swap list[i] with list[currentMinIndex] if necessary;
if (currentMinIndex != i) {
swaps++;
list[currentMinIndex] = list[i];
list[i] = currentMin;
}
}
System.out.println("The size of array is " + list.length);
System.out.println("No. of comparisons: " + comparisons);
System.out.println("No. of swaps: " + swaps + "\n\n");
}

private static void display(String name, double[] list)
{
System.out.println("The elements in the array " + name + " are");
for(int i = 0; i < list.length; i++)
{
if(i % 10 == 0)
System.out.println();
System.out.printf("%.2f ", list[i]);
}
System.out.println("\n-------------------");
}
public static void main(String[] args) {
final int NUM_ELEMENTS = 1000;
double[] lo2hi = new double[NUM_ELEMENTS];
double[] hi2lo = new double[NUM_ELEMENTS];
double[] random = new double[NUM_ELEMENTS];
for(int d = 1; d <= NUM_ELEMENTS; d++)
lo2hi[d-1] = d;
for(int d = 0; d < NUM_ELEMENTS; d++)
hi2lo[d] = NUM_ELEMENTS - d ;
for(int d = 1; d <= NUM_ELEMENTS; d++)
random[d-1] = Math.random();
//comment when large number of elements are being sorted
display("lo2hi", lo2hi);
display("hi2lo", hi2lo);
display("random", random);
////////////////
System.out.println("Sorting low2hi");
selectionSort(lo2hi);
System.out.println("Sorting hi2lo");
selectionSort(hi2lo);
System.out.println("Sorting random");
selectionSort(random);

}
}

Output analysis


The size of array is 1000
No. of comparisons: 499500

The size of array is 2000
No. of comparisons: 1999000

The size of array is 4000
No. of comparisons: 7998000

comparsions for 2000 vs 1000 elements is 1999000/ 499500 = 4.0002
comparsions for 4000 vs 2000 elements is 7998000/1999000 = 4.0001

This shows that when the size is doubled, the ratio of number of comparison for the 2 sizes is always 4. So when size is double from 1000 to 2000, the ratio of the comparisons made is 4. Same is case when 2000 is doubled to 4000, the ratio of no. of comparisons is 4 again.

output

The elements in the array lo2hi are

1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00  
11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00  
21.00 22.00 23.00 24.00 25.00 26.00 27.00 28.00 29.00 30.00  
31.00 32.00 33.00 34.00 35.00 36.00 37.00 38.00 39.00 40.00  
41.00 42.00 43.00 44.00 45.00 46.00 47.00 48.00 49.00 50.00  
51.00 52.00 53.00 54.00 55.00 56.00 57.00 58.00 59.00 60.00  
61.00 62.00 63.00 64.00 65.00 66.00 67.00 68.00 69.00 70.00  
71.00 72.00 73.00 74.00 75.00 76.00 77.00 78.00 79.00 80.00  
81.00 82.00 83.00 84.00 85.00 86.00 87.00 88.00 89.00 90.00  
91.00 92.00 93.00 94.00 95.00 96.00 97.00 98.00 99.00 100.00  
101.00 102.00 103.00 104.00 105.00 106.00 107.00 108.00 109.00 110.00  
111.00 112.00 113.00 114.00 115.00 116.00 117.00 118.00 119.00 120.00  
121.00 122.00 123.00 124.00 125.00 126.00 127.00 128.00 129.00 130.00  
131.00 132.00 133.00 134.00 135.00 136.00 137.00 138.00 139.00 140.00  
141.00 142.00 143.00 144.00 145.00 146.00 147.00 148.00 149.00 150.00  
151.00 152.00 153.00 154.00 155.00 156.00 157.00 158.00 159.00 160.00  
161.00 162.00 163.00 164.00 165.00 166.00 167.00 168.00 169.00 170.00  
171.00 172.00 173.00 174.00 175.00 176.00 177.00 178.00 179.00 180.00  
181.00 182.00 183.00 184.00 185.00 186.00 187.00 188.00 189.00 190.00  
191.00 192.00 193.00 194.00 195.00 196.00 197.00 198.00 199.00 200.00  
201.00 202.00 203.00 204.00 205.00 206.00 207.00 208.00 209.00 210.00  
211.00 212.00 213.00 214.00 215.00 216.00 217.00 218.00 219.00 220.00  
221.00 222.00 223.00 224.00 225.00 226.00 227.00 228.00 229.00 230.00  
231.00 232.00 233.00 234.00 235.00 236.00 237.00 238.00 239.00 240.00  
241.00 242.00 243.00 244.00 245.00 246.00 247.00 248.00 249.00 250.00  
251.00 252.00 253.00 254.00 255.00 256.00 257.00 258.00 259.00 260.00  
261.00 262.00 263.00 264.00 265.00 266.00 267.00 268.00 269.00 270.00  
271.00 272.00 273.00 274.00 275.00 276.00 277.00 278.00 279.00 280.00  
281.00 282.00 283.00 284.00 285.00 286.00 287.00 288.00 289.00 290.00  
291.00 292.00 293.00 294.00 295.00 296.00 297.00 298.00 299.00 300.00  
301.00 302.00 303.00 304.00 305.00 306.00 307.00 308.00 309.00 310.00  
311.00 312.00 313.00 314.00 315.00 316.00 317.00 318.00 319.00 320.00  
321.00 322.00 323.00 324.00 325.00 326.00 327.00 328.00 329.00 330.00  
331.00 332.00 333.00 334.00 335.00 336.00 337.00 338.00 339.00 340.00  
341.00 342.00 343.00 344.00 345.00 346.00 347.00 348.00 349.00 350.00  
351.00 352.00 353.00 354.00 355.00 356.00 357.00 358.00 359.00 360.00  
361.00 362.00 363.00 364.00 365.00 366.00 367.00 368.00 369.00 370.00  
371.00 372.00 373.00 374.00 375.00 376.00 377.00 378.00 379.00 380.00  
381.00 382.00 383.00 384.00 385.00 386.00 387.00 388.00 389.00 390.00  
391.00 392.00 393.00 394.00 395.00 396.00 397.00 398.00 399.00 400.00  
401.00 402.00 403.00 404.00 405.00 406.00 407.00 408.00 409.00 410.00  
411.00 412.00 413.00 414.00 415.00 416.00 417.00 418.00 419.00 420.00  
421.00 422.00 423.00 424.00 425.00 426.00 427.00 428.00 429.00 430.00  
431.00 432.00 433.00 434.00 435.00 436.00 437.00 438.00 439.00 440.00  
441.00 442.00 443.00 444.00 445.00 446.00 447.00 448.00 449.00 450.00  
451.00 452.00 453.00 454.00 455.00 456.00 457.00 458.00 459.00 460.00  
461.00 462.00 463.00 464.00 465.00 466.00 467.00 468.00 469.00 470.00  
471.00 472.00 473.00 474.00 475.00 476.00 477.00 478.00 479.00 480.00  
481.00 482.00 483.00 484.00 485.00 486.00 487.00 488.00 489.00 490.00  
491.00 492.00 493.00 494.00 495.00 496.00 497.00 498.00 499.00 500.00  
501.00 502.00 503.00 504.00 505.00 506.00 507.00 508.00 509.00 510.00  
511.00 512.00 513.00 514.00 515.00 516.00 517.00 518.00 519.00 520.00  
521.00 522.00 523.00 524.00 525.00 526.00 527.00 528.00 529.00 530.00  
531.00 532.00 533.00 534.00 535.00 536.00 537.00 538.00 539.00 540.00  
541.00 542.00 543.00 544.00 545.00 546.00 547.00 548.00 549.00 550.00  
551.00 552.00 553.00 554.00 555.00 556.00 557.00 558.00 559.00 560.00  
561.00 562.00 563.00 564.00 565.00 566.00 567.00 568.00 569.00 570.00  
571.00 572.00 573.00 574.00 575.00 576.00 577.00 578.00 579.00 580.00  
581.00 582.00 583.00 584.00 585.00 586.00 587.00 588.00 589.00 590.00  
591.00 592.00 593.00 594.00 595.00 596.00 597.00 598.00 599.00 600.00  
601.00 602.00 603.00 604.00 605.00 606.00 607.00 608.00 609.00 610.00  
611.00 612.00 613.00 614.00 615.00 616.00 617.00 618.00 619.00 620.00  
621.00 622.00 623.00 624.00 625.00 626.00 627.00 628.00 629.00 630.00  
631.00 632.00 633.00 634.00 635.00 636.00 637.00 638.00 639.00 640.00  
641.00 642.00 643.00 644.00 645.00 646.00 647.00 648.00 649.00 650.00  
651.00 652.00 653.00 654.00 655.00 656.00 657.00 658.00 659.00 660.00  
661.00 662.00 663.00 664.00 665.00 666.00 667.00 668.00 669.00 670.00  
671.00 672.00 673.00 674.00 675.00 676.00 677.00 678.00 679.00 680.00  
681.00 682.00 683.00 684.00 685.00 686.00 687.00 688.00 689.00 690.00  
691.00 692.00 693.00 694.00 695.00 696.00 697.00 698.00 699.00 700.00  
701.00 702.00 703.00 704.00 705.00 706.00 707.00 708.00 709.00 710.00  
711.00 712.00 713.00 714.00 715.00 716.00 717.00 718.00 719.00 720.00  
721.00 722.00 723.00 724.00 725.00 726.00 727.00 728.00 729.00 730.00  
731.00 732.00 733.00 734.00 735.00 736.00 737.00 738.00 739.00 740.00  
741.00 742.00 743.00 744.00 745.00 746.00 747.00 748.00 749.00 750.00  
751.00 752.00 753.00 754.00 755.00 756.00 757.00 758.00 759.00 760.00  
761.00 762.00 763.00 764.00 765.00 766.00 767.00 768.00 769.00 770.00  
771.00 772.00 773.00 774.00 775.00 776.00 777.00 778.00 779.00 780.00  
781.00 782.00 783.00 784.00 785.00 786.00 787.00 788.00 789.00 790.00  
791.00 792.00 793.00 794.00 795.00 796.00 797.00 798.00 799.00 800.00  
801.00 802.00 803.00 804.00 805.00 806.00 807.00 808.00 809.00 810.00  
811.00 812.00 813.00 814.00 815.00 816.00 817.00 818.00 819.00 820.00  
821.00 822.00 823.00 824.00 825.00 826.00 827.00 828.00 829.00 830.00  
831.00 832.00 833.00 834.00 835.00 836.00 837.00 838.00 839.00 840.00  
841.00 842.00 843.00 844.00 845.00 846.00 847.00 848.00 849.00 850.00  
851.00 852.00 853.00 854.00 855.00 856.00 857.00 858.00 859.00 860.00  
861.00 862.00 863.00 864.00 865.00 866.00 867.00 868.00 869.00 870.00  
871.00 872.00 873.00 874.00 875.00 876.00 877.00 878.00 879.00 880.00  
881.00 882.00 883.00 884.00 885.00 886.00 887.00 888.00 889.00 890.00  
891.00 892.00 893.00 894.00 895.00 896.00 897.00 898.00 899.00 900.00  
901.00 902.00 903.00 904.00 905.00 906.00 907.00 908.00 909.00 910.00  
911.00 912.00 913.00 914.00 915.00 916.00 917.00 918.00 919.00 920.00  
921.00 922.00 923.00 924.00 925.00 926.00 927.00 928.00 929.00 930.00  
931.00 932.00 933.00 934.00 935.00 936.00 937.00 938.00 939.00 940.00  
941.00 942.00 943.00 944.00 945.00 946.00 947.00 948.00 949.00 950.00  
951.00 952.00 953.00 954.00 955.00 956.00 957.00 958.00 959.00 960.00  
961.00 962.00 963.00 964.00 965.00 966.00 967.00 968.00 969.00 970.00  
971.00 972.00 973.00 974.00 975.00 976.00 977.00 978.00 979.00 980.00  
981.00 982.00 983.00 984.00 985.00 986.00 987.00 988.00 989.00 990.00  
991.00 992.00 993.00 994.00 995.00 996.00 997.00 998.00 999.00 1000.00  
-------------------
The elements in the array hi2lo are

1000.00 999.00 998.00 997.00 996.00 995.00 994.00 993.00 992.00 991.00  
990.00 989.00 988.00 987.00 986.00 985.00 984.00 983.00 982.00 981.00  
980.00 979.00 978.00 977.00 976.00 975.00 974.00 973.00 972.00 971.00  
970.00 969.00 968.00 967.00 966.00 965.00 964.00 963.00 962.00 961.00  
960.00 959.00 958.00 957.00 956.00 955.00 954.00 953.00 952.00 951.00  
950.00 949.00 948.00 947.00 946.00 945.00 944.00 943.00 942.00 941.00  
940.00 939.00 938.00 937.00 936.00 935.00 934.00 933.00 932.00 931.00  
930.00 929.00 928.00 927.00 926.00 925.00 924.00 923.00 922.00 921.00  
920.00 919.00 918.00 917.00 916.00 915.00 914.00 913.00 912.00 911.00  
910.00 909.00 908.00 907.00 906.00 905.00 904.00 903.00 902.00 901.00  
900.00 899.00 898.00 897.00 896.00 895.00 894.00 893.00 892.00 891.00  
890.00 889.00 888.00 887.00 886.00 885.00 884.00 883.00 882.00 881.00  
880.00 879.00 878.00 877.00 876.00 875.00 874.00 873.00 872.00 871.00  
870.00 869.00 868.00 867.00 866.00 865.00 864.00 863.00 862.00 861.00  
860.00 859.00 858.00 857.00 856.00 855.00 854.00 853.00 852.00 851.00  
850.00 849.00 848.00 847.00 846.00 845.00 844.00 843.00 842.00 841.00  
840.00 839.00 838.00 837.00 836.00 835.00 834.00 833.00 832.00 831.00  
830.00 829.00 828.00 827.00 826.00 825.00 824.00 823.00 822.00 821.00  
820.00 819.00 818.00 817.00 816.00 815.00 814.00 813.00 812.00 811.00  
810.00 809.00 808.00 807.00 806.00 805.00 804.00 803.00 802.00 801.00  
800.00 799.00 798.00 797.00 796.00 795.00 794.00 793.00 792.00 791.00  
790.00 789.00 788.00 787.00 786.00 785.00 784.00 783.00 782.00 781.00  
780.00 779.00 778.00 777.00 776.00 775.00 774.00 773.00 772.00 771.00  
770.00 769.00 768.00 767.00 766.00 765.00 764.00 763.00 762.00 761.00  
760.00 759.00 758.00 757.00 756.00 755.00 754.00 753.00 752.00 751.00  
750.00 749.00 748.00 747.00 746.00 745.00 744.00 743.00 742.00 741.00  
740.00 739.00 738.00 737.00 736.00 735.00 734.00 733.00 732.00 731.00  
730.00 729.00 728.00 727.00 726.00 725.00 724.00 723.00 722.00 721.00  
720.00 719.00 718.00 717.00 716.00 715.00 714.00 713.00 712.00 711.00  
710.00 709.00 708.00 707.00 706.00 705.00 704.00 703.00 702.00 701.00  
700.00 699.00 698.00 697.00 696.00 695.00 694.00 693.00 692.00 691.00  
690.00 689.00 688.00 687.00 686.00 685.00 684.00 683.00 682.00 681.00  
680.00 679.00 678.00 677.00 676.00 675.00 674.00 673.00 672.00 671.00  
670.00 669.00 668.00 667.00 666.00 665.00 664.00 663.00 662.00 661.00  
660.00 659.00 658.00 657.00 656.00 655.00 654.00 653.00 652.00 651.00  
650.00 649.00 648.00 647.00 646.00 645.00 644.00 643.00 642.00 641.00  
640.00 639.00 638.00 637.00 636.00 635.00 634.00 633.00 632.00 631.00  
630.00 629.00 628.00 627.00 626.00 625.00 624.00 623.00 622.00 621.00  
620.00 619.00 618.00 617.00 616.00 615.00 614.00 613.00 612.00 611.00  
610.00 609.00 608.00 607.00 606.00 605.00 604.00 603.00 602.00 601.00  
600.00 599.00 598.00 597.00 596.00 595.00 594.00 593.00 592.00 591.00  
590.00 589.00 588.00 587.00 586.00 585.00 584.00 583.00 582.00 581.00  
580.00 579.00 578.00 577.00 576.00 575.00 574.00 573.00 572.00 571.00  
570.00 569.00 568.00 567.00 566.00 565.00 564.00 563.00 562.00 561.00  
560.00 559.00 558.00 557.00 556.00 555.00 554.00 553.00 552.00 551.00  
550.00 549.00 548.00 547.00 546.00 545.00 544.00 543.00 542.00 541.00  
540.00 539.00 538.00 537.00 536.00 535.00 534.00 533.00 532.00 531.00  
530.00 529.00 528.00 527.00 526.00 525.00 524.00 523.00 522.00 521.00  
520.00 519.00 518.00 517.00 516.00 515.00 514.00 513.00 512.00 511.00  
510.00 509.00 508.00 507.00 506.00 505.00 504.00 503.00 502.00 501.00  
500.00 499.00 498.00 497.00 496.00 495.00 494.00 493.00 492.00 491.00  
490.00 489.00 488.00 487.00 486.00 485.00 484.00 483.00 482.00 481.00  
480.00 479.00 478.00 477.00 476.00 475.00 474.00 473.00 472.00 471.00  
470.00 469.00 468.00 467.00 466.00 465.00 464.00 463.00 462.00 461.00  
460.00 459.00 458.00 457.00 456.00 455.00 454.00 453.00 452.00 451.00  
450.00 449.00 448.00 447.00 446.00 445.00 444.00 443.00 442.00 441.00  
440.00 439.00 438.00 437.00 436.00 435.00 434.00 433.00 432.00 431.00  
430.00 429.00 428.00 427.00 426.00 425.00 424.00 423.00 422.00 421.00  
420.00 419.00 418.00 417.00 416.00 415.00 414.00 413.00 412.00 411.00  
410.00 409.00 408.00 407.00 406.00 405.00 404.00 403.00 402.00 401.00  
400.00 399.00 398.00 397.00 396.00 395.00 394.00 393.00 392.00 391.00  
390.00 389.00 388.00 387.00 386.00 385.00 384.00 383.00 382.00 381.00  
380.00 379.00 378.00 377.00 376.00 375.00 374.00 373.00 372.00 371.00  
370.00 369.00 368.00 367.00 366.00 365.00 364.00 363.00 362.00 361.00  
360.00 359.00 358.00 357.00 356.00 355.00 354.00 353.00 352.00 351.00  
350.00 349.00 348.00 347.00 346.00 345.00 344.00 343.00 342.00 341.00  
340.00 339.00 338.00 337.00 336.00 335.00 334.00 333.00 332.00 331.00  
330.00 329.00 328.00 327.00 326.00 325.00 324.00 323.00 322.00 321.00  
320.00 319.00 318.00 317.00 316.00 315.00 314.00 313.00 312.00 311.00  
310.00 309.00 308.00 307.00 306.00 305.00 304.00 303.00 302.00 301.00  
300.00 299.00 298.00 297.00 296.00 295.00 294.00 293.00 292.00 291.00  
290.00 289.00 288.00 287.00 286.00 285.00 284.00 283.00 282.00 281.00  
280.00 279.00 278.00 277.00 276.00 275.00 274.00 273.00 272.00 271.00  
270.00 269.00 268.00 267.00 266.00 265.00 264.00 263.00 262.00 261.00  
260.00 259.00 258.00 257.00 256.00 255.00 254.00 253.00 252.00 251.00  
250.00 249.00 248.00 247.00 246.00 245.00 244.00 243.00 242.00 241.00  
240.00 239.00 238.00 237.00 236.00 235.00 234.00 233.00 232.00 231.00  
230.00 229.00 228.00 227.00 226.00 225.00 224.00 223.00 222.00 221.00  
220.00 219.00 218.00 217.00 216.00 215.00 214.00 213.00 212.00 211.00  
210.00 209.00 208.00 207.00 206.00 205.00 204.00 203.00 202.00 201.00  
200.00 199.00 198.00 197.00 196.00 195.00 194.00 193.00 192.00 191.00  
190.00 189.00 188.00 187.00 186.00 185.00 184.00 183.00 182.00 181.00  
180.00 179.00 178.00 177.00 176.00 175.00 174.00 173.00 172.00 171.00  
170.00 169.00 168.00 167.00 166.00 165.00 164.00 163.00 162.00 161.00  
160.00 159.00 158.00 157.00 156.00 155.00 154.00 153.00 152.00 151.00  
150.00 149.00 148.00 147.00 146.00 145.00 144.00 143.00 142.00 141.00  
140.00 139.00 138.00 137.00 136.00 135.00 134.00 133.00 132.00 131.00  
130.00 129.00 128.00 127.00 126.00 125.00 124.00 123.00 122.00 121.00  
120.00 119.00 118.00 117.00 116.00 115.00 114.00 113.00 112.00 111.00  
110.00 109.00 108.00 107.00 106.00 105.00 104.00 103.00 102.00 101.00  
100.00 99.00 98.00 97.00 96.00 95.00 94.00 93.00 92.00 91.00  
90.00 89.00 88.00 87.00 86.00 85.00 84.00 83.00 82.00 81.00  
80.00 79.00 78.00 77.00 76.00 75.00 74.00 73.00 72.00 71.00  
70.00 69.00 68.00 67.00 66.00 65.00 64.00 63.00 62.00 61.00  
60.00 59.00 58.00 57.00 56.00 55.00 54.00 53.00 52.00 51.00  
50.00 49.00 48.00 47.00 46.00 45.00 44.00 43.00 42.00 41.00  
40.00 39.00 38.00 37.00 36.00 35.00 34.00 33.00 32.00 31.00  
30.00 29.00 28.00 27.00 26.00 25.00 24.00 23.00 22.00 21.00  
20.00 19.00 18.00 17.00 16.00 15.00 14.00 13.00 12.00 11.00  
10.00 9.00 8.00 7.00 6.00 5.00 4.00 3.00 2.00 1.00  
-------------------
The elements in the array random are

0.04 0.34 0.93 0.16 0.51 0.72 0.77 0.43 0.81 0.93  
0.88 0.88 0.67 0.97 0.11 0.47 0.77 0.10 0.86 0.90  
0.44 0.11 0.19 0.35 0.26 0.96 0.08 0.03 0.97 0.92  
0.84 0.39 0.26 0.50 0.53 0.69 0.83 0.70 0.85 0.87  
0.48 0.18 0.08 0.23 0.43 0.69 0.44 0.40 0.39 0.36  
0.94 0.82 0.96 0.73 0.69 0.41 0.29 0.57 0.64 0.57  
0.58 0.70 0.05 0.46 0.54 0.85 0.28 0.10 0.68 0.73  
1.00 0.95 0.65 0.91 0.75 0.87 0.38 0.41 0.38 0.20  
0.81 0.71 0.12 0.91 0.66 0.31 0.10 0.30 0.04 0.56  
0.40 0.85 0.82 0.53 0.21 0.05 0.13 0.19 0.39 0.21  
0.04 0.28 0.37 0.82 0.92 0.09 0.30 0.57 0.32 0.59  
0.50 0.27 0.70 0.12 0.44 0.98 0.10 0.51 0.96 0.25  
0.74 0.37 0.99 0.61 0.30 0.69 0.50 0.24 0.25 0.57  
0.83 0.72 0.47 0.02 0.96 0.19 0.17 0.55 0.88 0.35  
0.54 0.68 0.41 0.66 0.76 0.71 0.30 0.25 0.21 0.92  
0.21 0.58 0.83 0.36 0.76 0.04 0.79 0.35 0.12 0.01  
0.96 0.32 0.38 0.59 0.49 0.54 0.55 0.79 0.24 0.41  
0.19 0.08 0.03 0.20 0.48 0.88 0.25 0.41 0.18 0.27  
0.23 0.37 0.75 0.81 0.33 0.82 0.29 0.94 0.07 0.19  
0.63 0.62 0.44 0.48 0.89 0.53 0.17 0.31 0.88 0.02  
0.03 0.75 0.58 0.37 0.84 0.02 0.87 0.85 0.86 0.97  
0.45 0.10 0.02 0.58 0.29 0.99 0.55 0.32 0.08 0.23  
0.92 0.41 0.59 0.25 0.39 0.31 0.84 0.80 0.02 0.01  
0.12 0.95 0.71 0.48 0.44 0.63 0.81 0.93 0.76 0.22  
0.75 0.15 0.63 0.72 0.51 0.03 0.39 0.25 0.92 0.18  
0.52 0.68 0.46 0.85 0.44 0.89 0.78 0.18 0.12 0.27  
0.06 0.96 0.55 0.49 0.27 0.52 0.77 0.49 0.49 0.46  
0.88 0.88 0.94 0.18 0.73 0.72 0.45 0.07 0.77 0.66  
0.18 0.26 0.16 0.89 0.70 0.48 0.64 0.49 0.79 0.63  
0.04 0.71 0.26 0.89 0.49 0.88 0.28 0.19 0.99 0.34  
0.30 0.93 0.26 0.66 0.82 0.51 0.96 0.18 0.38 0.31  
0.89 0.26 0.76 0.99 0.13 0.53 0.34 0.05 0.03 0.31  
0.03 0.74 0.67 0.31 0.06 0.94 0.52 0.32 0.93 0.86  
0.14 0.22 0.97 0.74 0.22 0.43 0.05 0.75 0.62 0.87  
0.89 0.24 0.80 0.44 0.40 0.66 0.90 0.79 0.81 0.02  
0.47 0.60 0.97 0.70 0.32 0.52 0.32 0.90 0.87 0.99  
0.27 0.86 0.11 0.94 0.20 0.99 0.63 0.29 0.61 0.87  
0.24 0.65 0.13 0.06 0.14 0.46 0.09 0.93 0.22 0.16  
0.56 0.79 0.73 0.48 0.67 0.65 0.37 0.05 0.39 0.71  
0.20 0.21 0.76 0.63 0.32 0.40 0.61 0.20 0.43 0.13  
0.15 0.70 0.03 0.16 0.47 0.89 0.52 0.31 0.20 0.64  
0.39 0.38 0.67 0.08 0.59 0.03 0.74 0.78 0.27 0.19  
0.46 0.20 0.44 0.91 0.02 0.14 0.56 0.21 0.90 0.46  
0.36 0.37 0.53 0.65 0.52 0.73 0.60 0.04 0.02 0.78  
0.86 0.78 0.70 0.65 0.58 0.63 0.28 0.76 0.56 0.69  
0.86 0.33 0.22 0.11 0.07 0.33 0.84 0.52 0.04 0.58  
0.29 0.68 1.00 0.98 0.73 0.63 0.49 0.53 0.67 0.72  
0.10 0.79 0.62 0.84 0.13 0.19 0.19 0.16 0.02 0.16  
0.67 0.93 0.88 0.80 0.69 0.31 0.51 0.93 0.51 0.96  
0.79 0.38 0.18 0.17 0.97 0.73 0.85 0.30 0.09 0.02  
0.84 0.84 0.58 0.92 0.33 0.29 0.41 0.87 0.15 0.54  
0.97 0.67 0.59 0.88 0.77 0.84 0.34 0.31 0.81 0.67  
0.25 0.90 0.25 0.50 0.09 0.45 0.51 0.72 0.50 0.54  
0.30 0.59 0.99 0.19 1.00 0.32 0.32 0.35 0.13 0.26  
0.38 0.20 0.37 0.75 0.68 0.84 0.69 0.99 0.47 0.00  
0.64 0.36 0.07 0.39 0.08 0.50 0.83 0.31 0.16 0.14  
0.36 0.15 0.55 0.50 0.74 0.77 0.18 0.71 0.76 0.08  
0.32 0.86 0.94 0.85 0.83 0.32 0.38 0.36 0.83 0.52  
0.81 0.67 0.45 0.47 0.72 0.77 0.31 0.42 0.94 0.11  
0.80 0.28 0.02 0.81 0.66 0.05 0.64 0.46 0.04 0.73  
0.32 0.57 0.09 0.54 0.01 0.40 0.07 0.34 0.69 0.81  
0.93 0.34 0.38 0.21 0.88 0.97 0.01 0.57 0.65 0.91  
0.33 0.34 0.94 0.78 0.05 0.32 1.00 0.99 0.71 0.81  
0.66 0.52 0.05 0.57 0.66 0.31 0.24 0.15 0.73 0.76  
0.87 0.27 0.08 0.97 0.61 0.67 0.53 0.62 0.29 0.64  
0.14 0.58 0.26 0.46 0.14 0.16 0.36 0.05 0.87 0.16  
0.15 0.27 0.62 0.56 0.57 0.16 0.56 0.29 0.27 0.20  
0.52 0.63 0.35 0.59 0.73 0.83 0.72 0.95 0.84 0.38  
0.26 0.60 0.91 0.60 0.47 0.91 0.84 0.58 0.76 0.66  
0.20 0.49 0.33 0.47 0.51 0.70 0.41 0.88 0.09 0.91  
0.56 0.18 0.59 0.47 0.01 0.73 0.01 0.84 0.30 0.83  
0.29 0.09 0.97 0.45 0.36 0.58 0.65 0.47 0.32 0.86  
0.78 0.05 0.43 0.07 0.04 0.88 0.83 0.53 0.68 0.92  
0.09 0.46 0.43 0.13 0.18 0.92 0.60 0.34 0.22 0.16  
0.21 0.20 0.87 0.47 0.07 0.48 0.50 0.63 0.06 0.77  
0.00 0.70 0.81 0.61 0.71 0.64 0.98 0.70 0.99 0.94  
0.99 0.72 0.85 0.76 0.34 0.74 0.49 0.67 0.44 0.65  
0.68 0.27 0.68 0.57 0.76 0.28 0.38 0.44 0.49 0.78  
0.52 0.14 0.90 0.25 0.37 0.66 0.27 0.23 0.50 0.94  
0.65 0.93 0.54 0.71 0.39 0.17 0.48 0.75 0.80 0.52  
0.40 0.51 0.70 0.24 0.65 0.82 0.26 0.80 0.61 0.95  
0.56 0.52 0.54 0.64 0.40 0.85 0.71 0.16 0.08 0.10  
0.56 0.82 0.31 0.72 0.57 0.34 0.90 0.80 0.56 0.63  
0.87 0.82 0.10 0.74 0.93 0.28 0.44 0.17 0.99 0.50  
0.43 0.13 0.04 0.73 0.77 0.40 0.28 0.02 0.67 0.70  
0.82 0.86 0.01 0.41 0.07 0.03 0.98 0.36 0.49 0.02  
0.83 0.54 0.55 0.10 0.35 0.74 0.82 0.54 0.55 0.46  
0.34 0.00 0.69 0.49 0.79 0.70 0.66 0.16 0.95 0.76  
0.75 0.71 0.97 0.96 0.06 0.43 0.78 0.69 0.20 0.37  
0.12 0.18 0.43 0.50 0.66 0.95 0.90 0.32 0.50 0.15  
0.82 0.64 0.14 0.30 0.96 0.14 0.72 0.56 0.41 0.07  
0.93 0.04 0.41 0.89 0.25 0.29 0.02 0.47 0.26 0.45  
0.41 0.56 0.87 0.59 0.91 0.82 0.15 0.16 0.36 0.78  
0.72 0.52 0.79 0.48 0.65 0.18 0.34 0.14 0.69 0.86  
0.12 0.77 0.66 0.56 0.71 0.98 0.30 0.15 0.29 0.28  
0.97 0.07 0.85 0.77 0.40 0.73 0.04 0.79 0.45 0.12  
0.42 0.29 0.21 0.87 0.27 0.64 0.70 0.94 0.41 0.17  
0.57 0.41 0.25 0.70 0.48 0.80 0.08 0.70 0.57 0.39  
0.60 0.44 0.73 0.62 0.53 0.77 0.67 0.77 0.86 0.62  
0.08 0.42 0.30 0.42 0.17 0.04 0.29 0.83 0.14 0.33  
-------------------
Sorting low2hi
The size of array is 1000
No. of comparisons: 499500
No. of swaps: 0


Sorting hi2lo
The size of array is 1000
No. of comparisons: 499500
No. of swaps: 500


Sorting random
The size of array is 1000
No. of comparisons: 499500
No. of swaps: 994


Related Solutions

Write a Java application "WellFormedExpression.java". Start with the file attached here. Please read the comments and...
Write a Java application "WellFormedExpression.java". Start with the file attached here. Please read the comments and complete the function 'isWellFormed()'. It also has the main() to test the function with several input strings. Feel free to change and add more tests with different kinds of input data for correct implementation. Note that you need MyStack.java and Stackinterface.java in the same package. WellFormedExpression.java package apps; public class WellFormedExpression {    static boolean isWellFormed(String s) {        /**** Create a stack...
Create a Java class file for a Car class. In the File menu select New File......
Create a Java class file for a Car class. In the File menu select New File... Under Categories: make sure that Java is selected. Under File Types: make sure that Java Class is selected. Click Next. For Class Name: type Car. For Package: select csci2011.lab7. Click Finish. A text editor window should pop up with the following source code (except with your actual name): csci1011.lab7; /** * * @author Your Name */ public class Car { } Implement the Car...
java please        * implement zip method in Q1 class to merge two linkedlists into...
java please        * implement zip method in Q1 class to merge two linkedlists into one.        * The elements in the result are made by concatenating elements in different        * linkedlists one after one. The order of the elements matters.        * For example, merge(list1, list2) should return [1,5,2,4,3,3,4,2,5,1].        * You can assume that arr1 and arr2 has the same size.        * HINT: You should use ListIterator to make it...
Start with the partial model in the file attached. Marvel Pence, CEO of Marvel’s Renovations, a...
Start with the partial model in the file attached. Marvel Pence, CEO of Marvel’s Renovations, a custom building and repair company, is preparing documentation for a line of credit request from his commercial banker. Among the required documents is a detailed sales forecast for parts of 2020 and 2021: Sales Labor and Raw Materials May, 2020 $75,000 $80,000 June, 2020 $115,000 $75,000 July, 2020 $145,000 $105,000 August, 2020 $125,000 $85,000 September, 2020 $120,000 $65,000 October, 2020 $95,000 $70,000 November, 2020...
Start with the partial model in the file attached. Marvel Pence, CEO of Marvel’s Renovations, a...
Start with the partial model in the file attached. Marvel Pence, CEO of Marvel’s Renovations, a custom building and repair company, is preparing documentation for a line of credit request from his commercial banker. Among the required documents is a detailed sales forecast for parts of 2020 and 2021: Sales Labor and Raw Materials May, 2020 $75,000 $80,000 June, 2020 $115,000 $75,000 July, 2020 $145,000 $105,000 August, 2020 $125,000 $85,000 September, 2020 $120,000 $65,000 October, 2020 $95,000 $70,000 November, 2020...
Start with the partial model in the file attached. Marvel Pence, CEO of Marvel’s Renovations, a...
Start with the partial model in the file attached. Marvel Pence, CEO of Marvel’s Renovations, a custom building and repair company, is preparing documentation for a line of credit request from his commercial banker. Among the required documents is a detailed sales forecast for parts of 2020 and 2021: Sales Labor and Raw materials May 2020 $75,000 $80,000 June 2020 $115,000 $75,000 July, 2020 $145,000 $105,000 August 2020 $125,000 $85,000 September, 2020 $120,000 $65,000 October, 2020 $95,000 $70,000 November, 2020...
Follow the UML diagram and directions on the attached file to create a RectangularPrism class and...
Follow the UML diagram and directions on the attached file to create a RectangularPrism class and a RectangularPrismDemo class. --------------------------------------------------------------------------------------------------------------------------------------- RectangularPrism            - length: double       - width: double       - height: double + RectangularPrism() + RectangularPrism(l:double,w:double, h:double) + setLength(l:double):void + setWidth(w:double):void + setHeight(h:double):void +getLength():double +getWidth():double +getHeight():double +getVolume():double +getSurfaceArea():double +toString():String --------------------------------------------------------------------------------------------------------------------- Create a RectangularPrism class in its own file based on the UML Create a separate RectangularPrismDemo Class file to demonstrate your class by doing the following: Create two prisms,...
C# What to submit: One zip file named Ass3.zip This zip must contain one VS 2017...
C# What to submit: One zip file named Ass3.zip This zip must contain one VS 2017 solution named Ass3, which contains one C# Windows Forms App project also named Ass3 and the project contains a default form, Form1.cs and Program.cs. No change should be made in Program.cs, but your Form1 must be designed and implemented to satisfy the following requirements. **Do not submit only a single file of the solution or project. The whole solution folder of VS 2017 must...
Begin by creating a Java project with one class – Addition. Start with the class Addition...
Begin by creating a Java project with one class – Addition. Start with the class Addition as shown in Figure 12.2. This program uses dialog boxes for I/O to get two integers and display the result of adding them together. The program should run “as is”. Change the program so that it gets and adds two doubles instead of integers. When that is working get a third double using a dialog box. Add the three doubles together, and display the...
IN JAVA Searching and Sorting In An Integer List File IntegerList contains a Java class representing...
IN JAVA Searching and Sorting In An Integer List File IntegerList contains a Java class representing a list of integers. The following public methods are provided: ? IntegerList(int size)—creates a new list of size elements. Elements are initialized to 0. ? void randomize()—fills the list with random integers between 1 and 100, inclusive. ? void print()—prints the array elements and indices ? int search(int target)—looks for value target in the list using a linear (also called sequential) search algorithm. Returns...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT