
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
Concept explainers
Question

Transcribed Image Text:One 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 formula

Transcribed Image Text:}
In ouunu = 2*11 - 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 formula
OI, II
OI, III
© II, III
O I, II, III
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 3 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Consider a recursive function, called f, that computes powers of 3 using only the + operator. Assume n > = 0. int f(int n) { if (n == 0) return 1; return f(n-1) + f(n-1) + f(n-1); } Give an optimized version of f, called g, where we save the result of the recursive call to a temporary variable t, then return t+t+t. i got int g(int n) { if (n == 0) return 1; int t = g(n - 1); return t+t+t; } so now Write a recurrence relation for T(n), the number addition operations performed by g(n) in terms of n.arrow_forwardCan someone explain how the output of this recusrsive function is 5? I find recursion difficult to understand def R(n): if n<=0: return 20 return R(n-1)-n print(R(5))arrow_forward//write a recursion function that will find the largest interger in the string. Can you give me some feedback on this function public int findMax(String s,intmax) { if (s.length()== 0) return 1; for (int = 0 ; i > s.length() ;i++) if (s.charAt (i) > s.charAt(i) )) returnmax; returnmax;arrow_forward
- I need help with thisarrow_forwardWrite a recursive Python function named pgcd, to find and return the Greatest Common Divisor (GCD) of two numbers x and y passed in parameters. • Test it gcd (1234,4321) gcd (8192,192)arrow_forwardUsing recursion, write a function sum that takes a single argument n and computes the sum of all integers between 0 and n inclusive. Do not write this function using a while or for loop. Assume n is non-negative. def sum(n): """Using recursion, computes the sum of all integers between 1 and n, inclusive. Assume n is positive. >>> sum(1) 1 >>> sum(5) # 1 + 2 + 3+ 4+ 5 15 "*** YOUR CODE HERE ***"arrow_forward
- Which 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_forwardWhich of the following is the recursive definition for the function f(n)=2n with initial condition f(1) = 2? f(n) = 2n + f(n-1) f(n) = 2n - f(n-1) f(n) = 2n * f(n-1) f(n) = 2f(n − 1) Which of the following is the recursive definition for the function f(n)=5n+2 with initial condition f(1)=7? f(n) = 5n - f(n-1) f(n) = 5f(n-1) + 2 f(n) = 5n + f(n-1) f(n) = f(n-1) + 5arrow_forwardWhat 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_forward
- 1. Consider the following recursive function: def foo(n): if (n == 0): return 0 return n + foo(n - 1)a. What is foo(5) b. What is foo(10) c. Suppose that n + foo(n - 1) is changed to n * foo(n - 1). What is foo(5) now? d. What happens if foo(-1) is called?arrow_forwardq16arrow_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