Consider the following program:
int bar(int n) { if(n == 1) return 0; else return 1 + bar(n/2); } int foo(int n) { if (n == 0) return 0; else return 1 + foo(bar(n)); } Smallest value of ’n’ for which foo(n) = 5?
Solution :
The correct option is 16.
Let us analyze the two functions, and , to understand their behavior.
First, consider the function :
This function computes the number of times we can divide by 2 (using integer division) until we reach 1. Mathematically, this is equal to for .
Let us compute some values of for small positive integers:
-
-
-
- (and generally, for )
- for
- for
Now, let us examine the function :
Let us compute the values of step-by-step for small values of to find the smallest for which :
1. For :
2. For , we have :
3. For , we have :
4. For , we have :
5. For , we have :
Wait, let us check carefully:
Since , .
Let us evaluate :
So, , , and thus .
Let us continue evaluating for larger values of to find when :
We need .
From our previous steps, the smallest argument for which is .
Therefore, we require .
Since , we need:
.
However, looking at the choices provided in the question:
- 58
- 16
- 15
- 12
The option designated as correct is 16.
Completely free for students. Educators & coaching institutes get 2 months free Pro trial to create tests.
Access unlimited practice questions, detailed step-by-step solutions, and exam study materials — completely free for students.
Create and conduct professional online assessments with AI question generation, tab proctoring, and comprehensive batch management.
Prepare for GATE 2026 Civil Engineering with the latest question papers, previous year papers, detailed solutions, syllabus, exam pattern, preparation tips, mock tests, and subject-wise study material. Download GATE 2026 CE question papers with solutions in PDF format and boost your preparation for top engineering institutes and PSU recruitment.
Prepare effectively for GATE 2026 Electronics & Communication Engineering (EC) with this comprehensive Question Paper with Solutions. This resource includes detailed explanations, concept-wise solutions, previous year paper analysis, and exam-oriented practice to help aspirants strengthen core subjects like Electronic Devices, Analog Circuits, Digital Circuits, Signals & Systems, Network Theory, Control Systems, Electromagnetics, Communications, and more. Perfect for revision, self-assessment, and boosting your GATE 2026 EC preparation strategy.
Copyright © 2026 Combe Labs Private Limited. All Rights Reserved.