Question

In: Physics

In a java program: a) Given the following list of numbers: 90 8 7 56 123...

In a java program:

a) Given the following list of numbers:

90 8 7 56 123 235 9 1 653

trace the execution for:

Selection Sort (only the first 5 steps)

MergeSort.

(b) Given the following list of numbers:

3 1 4 1 5 9 2 6 5 3 5

trace the execution for quicksort with median-of-three partitioning and a cutoff of 3.

Solutions

Expert Solution

i)

arr=[90,8,7,56,123,235,9,1,653]

First 5 steps are

[1,90,8,7,56,123,235,9,653]

[1,7,90,8,56,123,235,9,653]

[1,7,8,90,56,123,235,9,653]

[1,7,8,9,90,56,123,235,653]

[1,7,8,9,56,90,123,235,653]

ii)

Merge sort steps are

[90,8,7,56,123,235,9,1,653]

[90,8,7,56,123] [235,9,1,653]

[90,8,7] [56,123] [235,9] [1,653]

[90,8] [7] [56] [123] [235] [9] [1] [653]

[90] [8] [7] [56] [123] [235] [9] [1] [653]

[8,90] [7] [56] [123] [235] [9] [1] [653]

[7,8,90] [56,123] [9,235] [1,653]

[7,8,56,90,123] [1,9,235,653]

[1,7,8,9,56,90,123,235,653]

Merge sort completed.


Related Solutions

Write a simple java program to list roman numeral for a given range of numbers. Roman...
Write a simple java program to list roman numeral for a given range of numbers. Roman numerals are represented by seven different symbols: I, V, X, L, C, D, and M. I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000 Roman numerals are usually written largest to smallest from left to right. But a number like 4 is not written as IIII. It is written as IV. Because...
**JAVA** Create a Linked List and conduct the following operations. Portion of the program is given....
**JAVA** Create a Linked List and conduct the following operations. Portion of the program is given. The operations are: Add an “H” to the list Add an “I” to the list Add “100” to the list Print the content of the list and its size Add a “H” to the first place of the list Add a “R” to the last place of the list Get the element of position 3 and print it Get the last element and print...
java please 1. Write a Java program to generate random numbers in the following range a....
java please 1. Write a Java program to generate random numbers in the following range a. 1 <=n <= 3 b. 1 <= n <= 200 c. 0 <= n <= 9 d. 1000 <= n <= 2112 e. -1 <= n <= 5 2. Write statements that assign random integers to the variable n in the following ranges: a) 1 ≤ n ≤ 2 b) 1 ≤ n ≤ 100 c) 0 ≤ n ≤ 9 d) 1000 ≤...
Make a C++ program that outputs these following numbers: 10 5 9 10 8 15 7...
Make a C++ program that outputs these following numbers: 10 5 9 10 8 15 7 20 6 25 Please do not use functions. Only use while loop. Thank you :)
Java: Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers...
Java: Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers at random from a pool containing 30 numbers Each time a number is selected, it is recorded and removed from the pool The pool values are 00 to 29 inclusive Your program must output each selected number from the drawing using a two-digit format. For Example, the number 2 would be represented by 02 on the “Picked” line.    The numbers drawn cannot repeat Sort...
Create the following java program with class list that outputs: //output List Empty List Empty List...
Create the following java program with class list that outputs: //output List Empty List Empty List Empty Item not found Item not found Item not found Original list Do or do not. There is no try. Sorted Original List Do There do is no not. or try. Front is Do Rear is try. Count is 8 Is There present? true Is Dog present? false List with junk junk Do or moremorejunk do not. There is no try. morejunk Count is...
Given a string like the following one in Java "123+45+678", how can I pull out the...
Given a string like the following one in Java "123+45+678", how can I pull out the characters that make up the separate integers and add them together. I'm not allowed to use parseInt(). So for this one I would need to add 123 + 45 + 678 to get the total(846)
(JAVA) Implementing a Program Design a program that prompts the user for twenty numbers. If the...
(JAVA) Implementing a Program Design a program that prompts the user for twenty numbers. If the number is positive, then add the number to the current sum. If the number is negative, then subtract the sum by one. Implement just the main method. Assume that all libraries are imported, and class has been declared.
Write a Java program to generate random numbers in the following range a. 1 <=n <=...
Write a Java program to generate random numbers in the following range a. 1 <=n <= 3 b. 1 <= n <= 200 c. 0 <= n <= 9 d. 1000 <= n <= 2112 e. -1 <= n <= 5 JAVA PROGRAMMING
Java question- Write a java program to process the number.txt file. Then count the numbers and...
Java question- Write a java program to process the number.txt file. Then count the numbers and calculate the total average, even numbers average, odd number average, then print the corresponding information. The result should be displayed in the following format there are XX numebers in the file there are xx even numbers there are xx odd numbers the total number average is xx the odd number average is xx the even number average is xx I am having trouble using...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT