Question: Consider the following function: int loop ( int N ) { / / Precondition: { N > = 0 } Random rand = new Random

Consider the following function:
int loop(int N){
//Precondition: {N >=0}
Random rand = new Random();
for(int i =1; i < N +1; i++){
if(i %2==0){
System.out.println("Begin iteration");
}
for(int j =1; j < Math.pow(8, Math.pow(3, i)); j*=2){
System.out.print("Type: "); //S1
int cond = rand.nextInt();
if(cond %3==0){
System.out.println("Thing");
}
else if(cond %2==0){
System.out.println("Something");
}
else{
System.out.println("Nothing");
}
}
}
}
Q 2.1
How many times will the line commented as S1 be run? Write your answer as a closed-form expression in terms of N. Show your work.
Q2.2
How many feasible paths do you have in this program? Again the answer should be expressed as a closed-form expression in terms of 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!