CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
56
You visited us 56 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following C-program fragment in which i, j, and n are integer variables. for (i = n, j = 0; i > 0; i / = 2, j + = I);
Let Val (j) = denote the value stored in the variable j after termination of the for loop. Which one of the following is true?

A
val (j) = (n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
val (j) = (n log n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
val (j) = (log n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
val (j) = (n)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
Open in App
Solution

The correct option is D val (j) = (n)
The frequency of the loop is i = i/2 = n/2 so after termination of for loop vol(j) = O(n) on average.

j = n + n2 + n22 + n2log2n = (n)

flag
Suggest Corrections
thumbs-up
0
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Shapes of Orbitals and Nodes
CHEMISTRY
Watch in App
Join BYJU'S Learning Program
CrossIcon