Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedthis is a recursive version for the first part, the second part must have a faster execution time and without recursion is suggested. image text in transcribedimage text in transcribed

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

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

Does it use a maximum of two typefaces or fonts?

Answered: 1 week ago