270 views

1 Answer

Best answer
1 votes
1 votes
complexity is O($\log _{2}n$)

simply consider cases as n= 2$^{2}$ , output=2

n = 2$^{3}$ , output=3

n = 2$^{k}$ , output=k = log$_{2}$2$^{k}$

solving in this way is easier thus it is O($\log _{2}n$)
selected by

Related questions

0 votes
0 votes
2 answers
1
radha gogia asked Jul 7, 2018
1,547 views
foo(int n) { for(int i=0 ; i<n ;i++) for(int j=i ; j<=i*i ;j++) if(j%i==0) { for(int k=0;k<j;k++) printf("hii"); } } How to proceed here for analyzing the time complexity...
1 votes
1 votes
2 answers
2
Anjana Babu asked Dec 21, 2016
522 views
Write C Program using Recursive Funtions for the Problem Described below and Analyse the Complexity Of the CodeProblemGiven an unordered array arr[] which contains n di...
0 votes
0 votes
0 answers
3