Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ADDED: I provided copiable code below. In that code there are methods that are incomplete. You are going to have to complete the methods as

ADDED:

I provided copiable code below. In that code there are methods that are incomplete. You are going to have to complete the methods as the prompt says.

Let me know if there are more questions.

At the bottom of the page I uploaded a copiable version of the code that is already existing for this homework. The point of this work is to implement the external sort, by using a normal sort phase, a 2 way merge to merge the sorted files, and heapsort. (Look at the prompt for further explanation of what to do). This JAVA code should NOT have any packages or compiling errors.

On the JAVA code that I uploaded you will see that on some of the methods it says COMPLETE THE METHOD. This is where you will implement what the prompt is asking you to do.

Thank you for your help please let me know if you have any questions.

-----JAVA-----

import java.util.*;

import java.io.*;

//CSUN Comp 282 Sp 21 Homework-2

//Implementing external sort:

//For sort phase using normal sort and

//for merge phase using 2way merge.

//Author:

public class xxxxxh2 {

//class used for search

int heap[], M;//M is largest array size

//use a short word for System.out to save typing

PrintStream prt = System.out;

// print file formatted k integers per line

private void prtfile(String fn, int k){

//declare variables

int i = 0, x;

prt.printf(" %s:",fn);

try {

Scanner inf = new Scanner(new File(fn));

while (inf.hasNext()) {

//read an input from fname

x = inf.nextInt();

prt.printf("%3d ", x);

i++;

if(i % k == 0) prt.printf(" ");

}//end while

//close file

inf.close();

}catch (Exception e){

prt.printf(" Ooops! Read Exception: %s", e);

}//end prtfile

//print n files

private void prtfiles(int n, int k) {

int i;

String fname;

for (i = 1; i

fname = "F" +i+".txt";

prtfile(fname, k);

}

}//end prtfiles

/ormalsort, creating arrays of size n

private int normalsort(){

//COMPLETE THIS METHOD

}//end normal sort

//2way merge n sorrted files

private int merge2way(int n){

//COMPLETE THIS METHOD

}// end merge2way

/way merge n sorted files

private int mergenway(int n){

//COMPLETE THIS METHOD

}//end mergenway

//merge 2 sorted files f1, f2 into f3

private int merge(String f1, String f2, String f3){

//COMPLETE THIS METHOD

}//end merge

//Heapsort heap[] with n integers

private void heapsort(int n){

//COMPLETE THIS METHOD

}//end sort

public static void main(String[] args) throws Exception{

int n, k = 15; // print 15 integers per line

xxxxxh2 srt = new xxxxxh2();

n = srt.normalsort(); // n is no. of sorted files created

srt.prtfiles(n, k);

System.out.printf(" Overall %4d sorted files are created", n);

srt.merge2way(n); // Merging n sorted files using 2-way merge

srt.mergenway(n); Merging n sorted files using n-way merge

//OPTIONAL Print execution time of both merges

System.out.printf(" Author: Gh. Dastghaibyfard Date: " +

java.time.LocalDate.now());

}//end main

}//end xxxxxH2

image text in transcribed

NOTE: Homeworks will not be graded if: Your complete homework is not in a SINGLE XXXXXH2.java file, where xxxxx is at most the 1st first 5 characters of your last name and H2 is the Homework number. Using package or have compile error. Does not compile or execute at the command prompt. It does not read input, from any input file. It's sent by email. Save the following java program into xxxxxH2.java and do as follow: a) Do not modify main method, except writing your name in line 83 and OPTIONAL part). b) Implement external sort: for sort phase use normal sort, for merge phase use two way merge to merge n sorted files (merge2way(n)), for array sort use heapsort. Also write merge(f1, f2, f3) to merge two sorted files f1 and f2 into f3.. c) OPTIONAL EXTRA POINT: Write mergenway(n) method and print execution time of both merges for initial input file over 10MB data. (100 Pts) d) A sample input is as follow:Note:Fist input is max array size for sort 10 84 82 52 80 96 85 75 75 82 87 92 89 57 94 93 92 63 99 87 72 73 56 74 50 84 62 72 55 86 75 74 100 83 60 53 68 89 67 66 65 72 94 73 54 98 96 85 75 75 82 87 92 89 To compile: javac xxxxxh2.java To execute: java xxxxxh2

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

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago