Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
30The following code is supposed to return n!, for positive n.
int factorial(int n){
if (n == 0)
return 1;
else
return (n + factorial(n - 1));
}
An analysis of the code using our "Three Question" approach reveals that:
Group of answer choices
it fails the base-case question.
it fails the smaller-caller question.
it fails the general-case question.
it passes on all three questions and is a valid
None of these is correct.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
Knowledge Booster
Similar questions
- Q1 The periodic function sin(2x) has multiple roots between x values of -5π and 5π. If xL = -15 and xU = 15, which of the following statements is true using a bracketed method? Select one: a. All roots will be returned b. The middle root will be returned c. The chosen bracket is invalid for bracketed methods d. A single root will be returned e. The algorithm will be stuck in an infinite loop Q2 Consider x and y to represent data points (xi,yi), where i = 1, 2, 3, … n. What is the length of pafter running the following command? p = polyval(x,y) Select one: a. n b. n - 1 c. n + 1 d. Empty variable e. 1 Q3 Consider a system of linear equations in the form of AX = B, where X is the unknown vector. Which of the following can be used to solve for X? Select one: a. X = A\B b. X = B./A c. X = inv(B)*A d. X = inv(A)./B e. X = B\Aarrow_forwardOne remarkably simple formula for calculating the value of p is the so-called Madhava-Leibniz series: p4 = 1-13+15-17+19-.... Consider the recursive function below to calculate the first n terms of this formula: double computePI(int n) { if (n <= 1) { return 1.0;} int oddnum = 2 * n - 1; if ((n % 2) == 0 { } return -1.0 oddnum + computePI(n − 1); } else { } return 1.0 / oddnum + computePI (n - 1); Which statements about the run-time performance of this function are true? 1.Each time this function is called it will invoke at least two more recursive calls II.The number of recursive calls this function will make is approximately equal to the value of the parameter variable n III.Not counting overhead, this function will be about as efficient as an iterative implementation of the same formulaarrow_forwardMake a code using Recursion The countSubstring function will take two strings as parameters and will return an integer that is the count of how many times the substring (the second parameter) appears in the first string without overlapping with itself. This method will be case insensitive. For example: countSubstring(“catwoman loves cats”, “cat”) would return 2 countSubstring(“aaa nice”, “aa”) would return 1 because “aa” only appears once without overlapping itself. public static int countSubstring(String s, String x) { if (s.length() == 0 || x.length() == 0) return 1; if (s.length() == 1 || x.length() == 1){ if (s.substring(0,1).equals(x.substring(0,1))){ s.replaceFirst((x), " "); return 1 + countSubstring(s.substring(1), x); } else { return 0 + countSubstring(s.substring(1), x); } } return countSubstring(s.substring(0,1), x) + countSubstring(s.substring(1), x); } public class Main { public static void main(String[] args) {…arrow_forward
- What is the value of sum?int w = 5;int sum = 0;for (int r = 1; r <= w; r++)for (int s = r; s <= w; s++)sum = sum + s;arrow_forwardThe following code is supposed to return nl, for positive n. An analysis of the code using our Three Question" approach reveals that: int factorial(int n)£ if (n -- e) return 1; else return (n - factoriel(n - 1)); it fails the smaller-caller question. it fails the general-case question. it passes on all three questions and is a valid algorithm. it fails the base-case question.arrow_forwardIn Kotlin, Write a tail-recursive function that takes a positive int n and uses a tail recursive helper function to calculate tand return 2^n (two to the power of n). Do not use math.powarrow_forward
- mplement a Java program that applies the Newton-Raphson's method xn+1 = xn – f(xn) / f '(xn) to search the roots for this polynomial function ax6 – bx5 + cx4 – dx3+ ex2 – fx + g = 0. Fill out a, b, c, d, e, f, and g using the first 7 digits of your ID, respectively. For example, if ID is 4759284, the polynomial function would be 4x6 – 7x5 + 5x4 – 9x3+ 2x2 – 8x + 4 = 0. The program terminates when the difference between the new solution and the previous one is smaller than 0.00001 within 2000 iterations. Otherwise, it shows Not Found as the final solution.arrow_forwardwhat could go wrong with the function show on the right? (tip: syntax error is not the answer) void goo(unsigned int n) { if (n==0) return; cout << n; goo(n-2); }arrow_forwardWhich is the base case for the following recursive function? void printOut( int n ) // Print nonnegative n { if( n >= 10 ) printOut( n / 10 ); printDigit( n % 10 ); } Group of answer choices A.if ( n >= 10 ) B.printOut( n/10 ); C.printDigit( n%10 ); D.if ( n >= 10) E.None of the abovearrow_forward
- What does the following recursive function do? int f(int n){ if (n==1) return 1; else returm n*f(n-1); } O sum of numbers from 1 to n Factorial of numbern Square of numbers from 1 to n Print the numbers from 1 to narrow_forwardPlease explain why this is the correct answer.arrow_forwardhi,it is wrong agai n fib(n) 2 1 2 1 2 1 2 1 2 1Number of recursive calls: 5 but have to:arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education