Question
*Use JAVA code. Implement merge sort using arrays . It must output the following: 1. The input (unsorted sequence). 2. The output (sorted sequence). 3.
*Use JAVA code.
Implement merge sort using arrays. It must output the following: 1. The input (unsorted sequence). 2. The output (sorted sequence). 3. The number of comparisons made.
Use the merge sort algorithm. It must be able to sort integers, as I will only be testing with integers. It must be able to support up to 20 integers. Since this is merge sort, your program must use recursion. When calculating the midpoint, it should round down to the nearest integer. E.g. 1/2 = 0, 2/2 = 1, 3/2=1, 4/2=2, etc. This is how its done in the book as well. You should also have your tester in the MergeSort.java file.In other words, both your class and tester should be in the same file. Your algorithm should also be able to support just one element as your input, as well as duplicates.
After executing your program, the console should output the following (the below input and output arrays are just examples): Unsorted Array 4 5 1 7 3 3 8 Sorted array 1 3 3 4 5 7 8
Number of comparisons: 14
Here are some more output examples:
Ex1.
Unsorted Array 1 2 1 Sorted array 1 1 2 Number of comparisons: 3
Ex 2.
Unsorted Array 1 Sorted array 1 Number of comparisons: 0
Ex2.
Unsorted Array 5 5 5 5 Sorted array 5 5 5 5 Number of comparisons: 4
Ex3.
Unsorted Array 1 2 3 4 5 6 7 Sorted array 1 2 3 4 5 6 7
Number of comparisons: 11
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started