The Gateway to Computer Science Excellence
0 votes
61 views

in Algorithms by Active (4.7k points) | 61 views
0
C?
0
Yes $C$ is correct. Please explain

I tried taking an input and calculating the return value but got $A$
0
for i=1 to 10k //i++

 for j=n to 1// n=n/2

       p++

for i=1 first full iteration for j increment p logn times// n ,n/2,n/4 ....1

so 10k * logn

so logn
0
n,n/2,n/4.... Isn't this nlogn
0
why are u adding

n n/2,n/4,n/8 ,,,,,,,,

how many iteration it take to reach from n to 1 i.e logn

its like

for(i=1;i<n;i=i*2) TC==?? logn
0
yes got it, thanks bro

1 Answer

0 votes
j>>=1 means rightshift 1

n/2^j =1

n=2^j

j=logn
by (201 points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,645 questions
56,616 answers
195,897 comments
102,364 users