Vidyalelo
Data Structure · Q381

Miscellaneous on Data Structures

Programming · Data Structure · question 381

Q381

What is the time complexity of the following code used to convert a decimal number to its binary equivalent? #include void dec_to_bin(int n) int arr[31],len = 0,i; if(n == 0) arr[0] = 0; len = 1; while(n != 0) arr[len++] = n % 2; n /= 2; for(i=len-1; i>=0; i--) printf("%d",arr[i]); int main() int n = 0; dec_to_bin(n); return 0;

A.
O(1)
B.
O(n)
C.
O(n2)
D.
O(logn)
Answer

Answer: Option D

Solution

Answer: Option D
No explanation is given for this question Let's Discuss on Board