Question: (1) Download the Recursive.java from BB Qwickly Content area, save it in a folder, say, users/myname/downloads/Recursive.java. (2) start a command prompt, cd to that folder

 (1) Download the Recursive.java from BB Qwickly Content area, save it
in a folder, say, users/myname/downloads/Recursive.java. (2) start a command prompt, cd to

(1) Download the Recursive.java from BB Qwickly Content area, save it in a folder, say, users/myname/downloads/Recursive.java. (2) start a command prompt, cd to that folder (3) javac Recursive.java (4) java Recursive 20000 (OK) (5) java Recursive 500000 (fail) This says that the recursive algorithm for computing the first n natural numbers is good for n=20000 but bad for 500000. We want to find out the critial N from which the algorithm starts to fail. Such a N depends on os setting, so call stack size. Using binary search manually. good-20000 bad = 500000 m = (20000+500000)/2 = 260000 in command line, java recursive 260000 if Ok, update good=260000, else bad=260000 Repeat m = (good + bad)/2 ... java Recursive m ... Do at least 10 iterations, to see how close the good is to bad. Task II: google search for "Can I change the stack size in my PC" stackoverflow public class Recursive { // using formula static int guass(int n) return n*(n+1)/2; // recursive version static int sum(int n) { if (n == 0) return 0; return sum(n-1) + n; in to , co I/iterative version static int sumi(int n) { int s = 0; for (int i=1; i 0) n = Integer.parseInt(args[0]); System.out.println(sum(n))

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!