search
Log In
0 votes
86 views

in Algorithms 86 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

Related questions

0 votes
2 answers
2
175 views
Given a text array $T[1…..n]$ and a pattern array $P[1….m]$ such that T and P are character taken from alphabet $\sum$, $\sum={a,b,c,…..z}$. String matching problem is to find all the occurence of P in T. A pattern occur with shift s in T if $P[1…..m]=T[s+1,…...s+m]$. Consider $T=bacacbaacacac$ $P=cac$ The sum of the value of all s is ________
asked Jan 14, 2019 in Algorithms Gupta731 175 views
...