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...
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 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 ≤...
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)
Given the sequence of numbers: 20, 7, 34, 29, 43, 40, 8, 12, 30, 42 (a)[7...
Given the sequence of numbers: 20, 7, 34, 29, 43, 40, 8, 12, 30, 42 (a)[7 pts] Show the resulting BST after inserting the numbers as keys. (b)[9 pts] What will be the resulting tree if you delete the root? Show the tree and explain the steps taken in deleting the root according to the delete procedure we discussed in class. (c)[9 pts] Can you reorder the original sequence of numbers to obtain a tree of a smaller height? If,...
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are...
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are divisible by 3. Arrange these numbers in a list called “result”. Hint: similar to page 9 in the slides.
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT