Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



Consider the following recursive Java function $f$ that takes two long arguments and returns a float value:

public static float f(long m, long n) {
float result = (float)m / (float)n;
if (m < 0 || n < 0) return 0.0f;
else result -= f(m * 2, n * 3);
return result;
}

Which of the following real values best approximates the value of $f(1,3)$?





Solution


$f(1,3)=\frac{1}{3}-f(2,9)$

$=\frac{1}{3}-\frac{2}{9}+\frac{4}{27}-\frac{8}{81}+\cdots$

This is a geometric series with first term $\frac{1}{3}$ and common ratio $-\frac{2}{3}$.

Sum:

$\frac{\frac{1}{3}}{1-(-\frac{2}{3})}=\frac{\frac{1}{3}}{\frac{5}{3}}=\frac{1}{5}=0.2$


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...