Question: this is a recursive version for the first part, the second part must have a faster execution time and without recursion is suggested. I require

this is a recursive version for the first part, the second partthis is a recursive version for the first part, the second part must have a faster execution time and without recursion is suggested. must have a faster execution time and without recursion is suggested. Irequire help with a version 2, one that does not use recursion,

I require help with a version 2, one that does not use recursion, in Java. Thank you:)

import java.io.*; import java.util.*; public class RecursiveVersion1 { public static void main(String[] args) throws Exception String ans=""; System.out.println("Enter Long String: "); Scanner s=new Scanner(System.in); String longStr=s.nextLine(); while(true){ System.out.println("Enter Short String or -1 for exit"); Long startTime = System.nano Time(); String shortStr=s.nextLine(); if(shortStr.equals("-1")) { break; }// will end the program and exit if no more short strings need to be checked FileWriter fw=new FileWriter( fileName: "output.txt", append: true); // for the output Permu( shortStr, ans, longStr, fw); long endTime = System.nanoTime(); FileWriter fwl=new Filewriter fileName: "timings.txt", append: true); // for time observation (in seconds) fwi.writel str: longStr+""+shortStr+""+"Execution time: : "+""+(endTime-start Time)/1000000000.0+" s "); // converting it to seconds instead of nanoseconds fwi.close(); fw.close(); 31 static void Permu(String str, String ans, String longStr, Filewriter fw) throws Exception 36 37 if (str. Length() == 0) { int p=longstr.indexOf(ans); System.out.println(ans); fw.writestr: ans+" "); if(p!=-1){ System.out.println("Found one match: "+ans+" is in "+longStr+" at location "+p); fw.write( str: "Found one match: "+ans+" is in "+LongStr+" at location "+p+" "); return; for (int i = b; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!