Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 4 : 9 calls / 9 कॉल
Advertisement
Detailed Solution
सही उत्तर 9 calls / 9 कॉल है।
Key Points
Helpful?
Question:
Consider fun(n): if n ≤ 1 return 1; else return fun(n−1) + fun(n−2). Counting the initial call, how many total function calls occur when evaluating fun(4)? / fun(n) पर विचार करें: यदि n ≤ 1 तो 1 लौटाएँ; अन्यथा fun(n−1) + fun(n−2) लौटाएँ। प्रारंभिक कॉल सहित fun(4) के मूल्यांकन में कुल कितने फंक्शन कॉल होंगे?
1.
5 calls / 5 कॉल
2.
7 calls / 7 कॉल
3.
8 calls / 8 कॉल
4.
9 calls / 9 कॉल
Correct Answer: 9 calls / 9 कॉल
Call tree: fun(4) → fun(3), fun(2); fun(3) → fun(2), fun(1); each fun(2) → fun(1), fun(0). Total = 1 + 1 + 2 + 3 + 2 = 9 calls. / कॉल वृक्ष: fun(4) → fun(3), fun(2); fun(3) → fun(2), fun(1); प्रत्येक fun(2) → fun(1), fun(0)। कुल = 1 + 1 + 2 + 3 + 2 = 9 कॉल।
Downloaded from PrepSnap (prepsnap.in)