Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java program..... Your colleague has 15 years of log files full of performance data. The data needs to be sorted, but the file sizes are

Java program.....

Your colleague has 15 years of log files full of performance data. The data needs to be sorted, but the file sizes are so big that it's impossible to load them all into memory at once. Your colleague decided to use a merge sort to divide the data into smaller chunks, sort them recursively, then merge results to produce the final sorted file with all data.

Your task is to write the core Merge Step function for the process. This function needs to combine two sorted subarrays into a single, sorted subarray

Your program should:

Compare the two unused lowest elements in each of the subarrays as a pair

Copy the first of the two values to the resulting array based on standard ASCII/UTF-8 sort order

Repeat steps 1 and 2 until one of the arrays is empty

Finally, copy remaining data in the non-empty subarray to the resulting array

Input:

Two comma-separated, sorted arrays of alphanumeric characters (UTF-8). The pair of arrays are separated by a semicolon.

For example: 1,4,7,8;2,3,5,6

Output:

Write the merged and sorted result as comma-separated elements on the first line.

Write each pair that was compared during merge process on the second line. Elements in each pair must be sorted and comma separated then enclosed in parenthesis.

For example: 1,2,3,4,5,6,7,8 (1,2)(2,4)(3,4)(4,5)(5,7)(6,7)

Test 1

Test InputDownload Test 1 Input

1,4,7,8;2,3,5,6

Expected OutputDownload Test 1 Output

1,2,3,4,5,6,7,8 (1,2)(2,4)(3,4)(4,5)(5,7)(6,7)

Test 2

Test InputDownload Test 2 Input

H,L,M,P,P,R,S,b,d,i,n,o,o,p,s;1,5,5,6,7,8,C,U,V,V,W,f,h,r,s

Expected OutputDownload Test 2 Output

1,5,5,6,7,8,C,H,L,M,P,P,R,S,U,V,V,W,b,d,f,h,i,n,o,o,p,r,s,s (1,H)(5,H)(5,H)(6,H)(7,H)(8,H)(C,H)(H,U)(L,U)(M,U)(P,U)(P,U)(R,U)(S,U)(U,b)(V,b)(V,b)(W,b)(b,f)(d,f)(f,i)(h,i)(i,r)(n,r)(o,r)(o,r)(p,r)(r,s)(s,s)

Test 3

Test InputDownload Test 3 Input

B,E,E,F,J,N,O,P,U,W;D,G,J,L,N,R,S,V,X,Y

Expected OutputDownload Test 3 Output

B,D,E,E,F,G,J,J,L,N,N,O,P,R,S,U,V,W,X,Y (B,D)(D,E)(E,G)(E,G)(F,G)(G,J)(J,J)(J,L)(L,N)(N,N)(N,R)(O,R)(P,R)(R,U)(S,U)(U,V)(V,W)(W,X)

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

Students also viewed these Databases questions