I just need help filling in the final blank. (I’m not sure if it’s “n-c-1” or “n-c+1” or something else entirely.)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
I just need help filling in the final blank. (I’m not sure if it’s “n-c-1” or “n-c+1” or something else entirely.)
Here is a recursive method which computes n! for n> 0:
//Precondition: n > 0
int factorial (int n) {
if (n < 3) {
return n;
} else {
return factorial (n
1) * n;
Suppose we are going to analyze this algorithm to determine the time complexity.
First, note the method's precondition is n> 0. A precondition is a condition or "rule" which must be
true or hold in order for the function to produce a correct result. If a method's precondition is not
met, then there is no guarantee the method will operate correctly. Enforcing preconditions in the
code is the job of the programmer writing the method. This specific precondition means that the
factorial() parameter n must be greater than zero of the method may not return the correct result.
Next, recall from your knowledge of the factorial function that 1! = 1 and 2! = 2. And recall that every
recursive algorithm must specify a base case which is executed when the base case condition is
satisfied. In factorial(), when n< 3 (and > 0 by the precondition) then we return n, which will be 1
when n = 1 and 2 when n = 2.
In analyzing the time complexity of an algorithm, one must determine the key operation and then
derive a function f(n) which counts or specifies how many times the key operation is performed as
a function of the problem size, n. The key operation is the operation that is performed the most
number of times and is generally an operation which is at the heart of the algorithm. In factorial(n)
the key operation is the multiplication operation because that is the operation which is performed
the most number of times and multiplication is central to the procedure for computing n!
Transcribed Image Text:Here is a recursive method which computes n! for n> 0: //Precondition: n > 0 int factorial (int n) { if (n < 3) { return n; } else { return factorial (n 1) * n; Suppose we are going to analyze this algorithm to determine the time complexity. First, note the method's precondition is n> 0. A precondition is a condition or "rule" which must be true or hold in order for the function to produce a correct result. If a method's precondition is not met, then there is no guarantee the method will operate correctly. Enforcing preconditions in the code is the job of the programmer writing the method. This specific precondition means that the factorial() parameter n must be greater than zero of the method may not return the correct result. Next, recall from your knowledge of the factorial function that 1! = 1 and 2! = 2. And recall that every recursive algorithm must specify a base case which is executed when the base case condition is satisfied. In factorial(), when n< 3 (and > 0 by the precondition) then we return n, which will be 1 when n = 1 and 2 when n = 2. In analyzing the time complexity of an algorithm, one must determine the key operation and then derive a function f(n) which counts or specifies how many times the key operation is performed as a function of the problem size, n. The key operation is the operation that is performed the most number of times and is generally an operation which is at the heart of the algorithm. In factorial(n) the key operation is the multiplication operation because that is the operation which is performed the most number of times and multiplication is central to the procedure for computing n!
For this question, fill in the blanks by specifying the call number and associated value of the
parameter variable n. The call from main() to factorial(n) is call 1, the recursive call to factorial(n - 1)
is call 2, the recursive call to factorial(n - 2) is call 3, etc. For each recursive call, the passed
argument will be 1 less than the parameter variable n. Note that during each call, we perform zero
or more multiplications but you do not need to complete that column for this question.
Important Note: you will be entering either integer constants or mathematical expressions for the
call number and/or the value of parameter variable n. This type of question is a multiple fill-in-the-
blank question and Canvas scores this type of question by performing a character-by-character
match of the string you enter with the string for the correct answer. In order to ensure that you do
not lose points, please format your entered strings to include parentheses only in the locations
where they are required based on the Java operator precedence rules so the correct operations will
be performed. Also, do not include any spaces in your answer. For example, if your answer is A + (B
- C) then you would enter A+B-C, omitting the spaces and the parentheses since their omission
does not mathematically alter the expression. On the other hand, if your answer is 3 - (B - C) then
you would enter 3-(B-C), again omitting the spaces but not the parentheses because omitting them
would change the value which is calculated, i.e., 3-(B-C) does not equal 3-B-C.
#3
Call Num
Param n
Multiplications
1
In
n 1
n-2
..
C
...
n-2
n-1
Transcribed Image Text:For this question, fill in the blanks by specifying the call number and associated value of the parameter variable n. The call from main() to factorial(n) is call 1, the recursive call to factorial(n - 1) is call 2, the recursive call to factorial(n - 2) is call 3, etc. For each recursive call, the passed argument will be 1 less than the parameter variable n. Note that during each call, we perform zero or more multiplications but you do not need to complete that column for this question. Important Note: you will be entering either integer constants or mathematical expressions for the call number and/or the value of parameter variable n. This type of question is a multiple fill-in-the- blank question and Canvas scores this type of question by performing a character-by-character match of the string you enter with the string for the correct answer. In order to ensure that you do not lose points, please format your entered strings to include parentheses only in the locations where they are required based on the Java operator precedence rules so the correct operations will be performed. Also, do not include any spaces in your answer. For example, if your answer is A + (B - C) then you would enter A+B-C, omitting the spaces and the parentheses since their omission does not mathematically alter the expression. On the other hand, if your answer is 3 - (B - C) then you would enter 3-(B-C), again omitting the spaces but not the parentheses because omitting them would change the value which is calculated, i.e., 3-(B-C) does not equal 3-B-C. #3 Call Num Param n Multiplications 1 In n 1 n-2 .. C ... n-2 n-1
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY