for (int j=0,k=0; j<n; j++)
for (double m=1; m<n; m*=2)
k++;
I think it’s O(n^2) but I’m not certain. I’m working on a practice problem and I have the following choices:
- O(n^2)
- O(2^n)
- O(n!)
- O(n log(n))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Its O(nlog2n). The code block runs n*log2n times.
Suppose
n=16; Then the first loop runs 16 (=n) times. And the second loops runs 4(=log2n) times (m=1,2,4,8). So the inner statementk++runs 64 times = (n*log2n) times.