Question

In: Computer Science

1.If one statement is nested within another statement, as in a loop or recursive call, what...

1.If one statement is nested within another statement, as in a loop or recursive call, what is the running time of the two statements when considered as a block?

the running time for the inner statement added to the running time for the outer statement

the running time for the inner statement multiplied by the running time for the outer statement

the running time for the inner statement divided by the running time for the outer statement

the running time for the outer statement divided by the running time for the inner statement

2. Which of the following is false regarding a recursive algorithm?

It should proceed towards a base case.

Each recursive call places another activation record on the stack.

It will always be more efficient than a corresponding iterative solution.

Each recursive call should operate on a smaller version of the original problem

3. What will happen if you execute a recursive algorithm that does not have a base case?

The algorithm will immediately fail.

The algorithm will execute, but it will take much longer to terminate than it would if it had a base case.

The algorithm will never terminate.

It can not be said what will happen with only the given information

4. What is the advantage of using dynamic programming?

Dynamic programming will work with dynamic data instead of static data (i.e., data that do not change).

Dynamic programming allows a recursive algorithm to be used, but prevents the algorithm from solving the same instance of a problem more than once.

Dynamic programming is an iterative, rather than a recursive technique, and thus performs more efficiently.

Dynamic programming is the only way to handle multiple base cases in a recursive problem

Solutions

Expert Solution

Answer)
1. the running time for the inner statement multiplied by the running time for the outer statement

When the outer loop and inner loop are there the running time is the multiplication of the running time of inner and outer.

2. The below is false:
It will always be more efficient than a corresponding iterative solution.

As iteration is always more efficient than the recursion calls.

3. If we execute a recursive algorithm that does not have a base case:

The algorithm will never terminate.

The algorithm/program will infinitely execute as it does not have a base class.

4. The advantage of using dynamic programming is:

Dynamic programming allows a recursive algorithm to be used, but prevents the algorithm from solving the same instance of a problem more than once.

Dynamic programming uses the recursion but using dynamic programming we are not calculating the same obtained results repeatedly and thus it is beneficial and faster.


Related Solutions

Be able to determine the runtime complexity of: A Java assignment statement A single loop Nested...
Be able to determine the runtime complexity of: A Java assignment statement A single loop Nested loop Given that for any polynomial of degree n, p(x) = anxn + an-1 xn-1 + …a1x + a0, p(x) = O(xn).  Show that: an expression such as the following                                                               4x3 + 7x2 + 12 is O(x3), by finding the witnesses, C and k.       Which of the following statements are true?                                              The running time of a loop is, at most, the running time of...
Be able to determine the runtime complexity of: A Java assignment statement A single loop Nested...
Be able to determine the runtime complexity of: A Java assignment statement A single loop Nested loop Given that for any polynomial of degree n, p(x) = anxn + an-1 xn-1 + …a1x + a0, p(x) = O(xn).              Show that:            an expression such as the following                                                               4x3 + 7x2 + 12 is O(x3), by finding the witnesses, C and k.      Which of the following statements are true?                                              The running time of a loop is, at most, the running time of...
Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer...
Create a PL/SQL anonymous block that uses a nested loop (inner loop 1 to 15; outer loop 1 to 5) to perform computations using the SQL functions, ABS, EXP, SQRT, ROUND, MIN, MAX, LOG, MOD, REMAINDER and POWER The outer loop will use the functions, ABS, EXP, SQRT, ROUND to display the following messages (must be “ The absolute value of <outer loop index> is <value>” “ The value of e to the <outer loop index> power is <value>” “...
C++ Recursive Functions: Please call functions in a main function as well. 1. A recursive function...
C++ Recursive Functions: Please call functions in a main function as well. 1. A recursive function that print the reverse of a string. (e.g., void printReverse(string exp)). For example, if exp =”coding”, then the function should print out “gnidoc”. 2. Implement a non-recursion-based binary search function. Convert this function into a recursion-based function. 3. Implement a recursive and non-recursive Fibonacci function.
Please use Microsoft excel. Using a Nested Loop, what is the equation to solve for letter...
Please use Microsoft excel. Using a Nested Loop, what is the equation to solve for letter grade Nested loop Student ID Grade Letter Grade 1 5 If score is Then return 2 55 Greater than 89 A 3 86 From 80 to 89 B 5 64 From 70 to 79 C 6 25 from 60 to 69 D 7 56 less than 60 F 8 58 9 99 10 90 11 28
3) Create a nested structure (one structure that contains another) and print out all the fields...
3) Create a nested structure (one structure that contains another) and print out all the fields in both structures. The main structure should have fields for: movie name and the year it was released. The extended structure should include the original structure as well as fields for: Lead actor, genre and runtime. In C 4) Create a structure for an employee which contains a field for: first name, last name, id and salary. Then use printf and scanf to fill...
I need these written in shell code 1.nested loop. e.g. 1*2 + 2*3 + 3*4 +...
I need these written in shell code 1.nested loop. e.g. 1*2 + 2*3 + 3*4 + ...(n-1)*n. (Only nested loops) 2.Fibonacci numbers.
C++ Language Implement a two-dimensional image using a nested loop. 1) Create an integer constant DIM...
C++ Language Implement a two-dimensional image using a nested loop. 1) Create an integer constant DIM and set it equal to 5. 2) Use a nested loop to print the output in terms of DIM. Example output: ***** *---* *---* *---* *****
Auditing Questions 1) What do you call the type of organization that keeps track of another...
Auditing Questions 1) What do you call the type of organization that keeps track of another company's equity-related transactions? 2) What area do we always assume that risks of fraud exist and that if we do not assume, we need to document our conclusion? 3) What statistical distribution pertains to the Test of Controls? 4) What does PPC stand for? 5) Which publicly traded companies are required to have their internal control audited?
Using Eclipse (Pyramid) Print out the following pyramid using nested loop. 1 12 123 1234 12345...
Using Eclipse (Pyramid) Print out the following pyramid using nested loop. 1 12 123 1234 12345 1) the source code (.java file), and 2) the screenshot of running results of each question.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT