...
UGC NET CS 2004 Dec-Paper-2
March 13, 2024
UGC NET CS 2004 Dec-Paper-2
March 13, 2024
UGC NET CS 2004 Dec-Paper-2
March 13, 2024
UGC NET CS 2004 Dec-Paper-2
March 13, 2024

Question 10742 – Programming

The function f is defined as follows:

int f (int n) {
       if (n <= 1) return 1;
       else if (n % 2  ==  0) return f(n/2);
       else return f(3n - 1);
} 

Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
(i) The function f terminates for finitely many different values of n ≥ 1.
(ii) The function f terminates for infinitely many different values of n ≥ 1.
(iii) The function f does not terminate for finitely many different values of n ≥ 1.
(iv) The function f does not terminate for infinitely many different values of n ≥ 1.
Which one of the following options is true of the above?

Correct Answer: D

Question 24 Explanation: 
The function can be terminated for all the values which can have factor of 2{(2-x)2 == 0}, so (i) is false and (ii) is true.
→ Let n=3, then it is terminated in 2nd iteration.
→ Let n=5, then sequence is 5→14→7→20→10 and it will repeat.
→ Any number with factor 5 and 2 leads to infinite recursion.
So, (iv) is True and (iii) is False.
A
(i) and (iii)
B
(i) and (iv)
C
(ii) and (iii)
D
(ii) and (iv)
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!