GATE CS 2018 (Forenoon) — Question 42

AlgorithmsAsymptotic Analysis (O, Omega, Theta Complexities)MCQ2 marks · −2/3 if wrongMedium

Consider the following C code. Assume that unsigned long int type length is 64 bits.
c
1unsigned long int fun(unsigned long int n){
2    unsigned long int i, j = 0, sum = 0;
3    for (i = n; i > 1; i = i/2) j++;
4    for ( ; j > 1; j = j/2) sum++;
5    return(sum);
6}
7
The value returned when we call fun with the input \(2^{40}\) is
  1. A
    4
  2. B
    5
  3. C
    6
  4. D
    40
Practise the full 2018-FN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkIntroduction to Algorithms (CLRS)The standard reference behind most GATE algorithm questions.
Practise more on Asymptotic Analysis (O, Omega, Theta Complexities)Timed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group