Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Arrays; public class MergeSort extends ConsoleProgram { /* * Do not make changes to this method! */ public void run() { int[] array1 =

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

import java.util.Arrays;

public class MergeSort extends ConsoleProgram { /* * Do not make changes to this method! */ public void run() { int[] array1 = {9, 8, 7, 6, 5, 4, 3, 2, 1}; int[] array2 = {5, 6, 4, 8, 9, 7, 3, 1, 2}; System.out.print("First array: "); System.out.println(Arrays.toString(array1)); System.out.print("Second array: "); System.out.println(Arrays.toString(array2)); System.out.println();

// sort first array mergeSort(array1); // sort second array mergeSort(array2);

System.out.print("First array sorted: "); System.out.println(Arrays.toString(array1)); System.out.print("Second array sorted: "); System.out.println(Arrays.toString(array2)); } /* * Merge sort takes in an array and sorts it. */ public static void mergeSort(int[] arr) { if (arr.length

image text in transcribed

RUN CODE TEST CASES ASSIGNMENT DOCS GRADE MORE 10 points Status: Not Submitted Mergesort is a complicated algorithm, but how complicated is it? In this exercise, we'll be taking our example code from before and adding a cool feature: at every recursive step, print out to the console what the two halves are that are going to be merged together. O 8.7.4: Explore Merge Sort 1 import java.util.Arrays; 2 public class MergeSort extends ConsoleProgram 4- 5 /* * Do not make changes to this method! */ public void run() 9- int[] array1 = (9, 8, 7, 6, 5, 4, 3, 2, 1}; int[] array2 = (5, 6, 4, 8, 9, 7, 3, 1, 2}; 10 %3D 11 12 System.out.print("First array: "); System.out.printin(Arrays.toString(array1)); System.out.print("Second array: "); System.out.println(Arrays.toString(array2)); System.out.println(); 13 14 15 16 17 18 // sort first array mergeSort(array1); // sort second array mergeSort(array2); 19 20 21 22 23 System.out.print("First array sorted: "); System.out.println(Arrays.toString(array1)); System.out.print("Second array sorted: "); System.out.printin(Arrays.tostring(array2)); 24 25 26 27 28 29 30 * Merge sort takes in an array and sorts it. */ public static void mergeSort(int[] arr) 31 32 33 34- if (arr,length

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

How can the Internet be helpful in a job search? (Objective 2)

Answered: 1 week ago