What is the running time of the following piece of code ?
for(k=1; k<=n; k*=2)
{
for(i=0; i<k; i++)
{
for(j=0; j<n; j+=2)
sum=sum+1;
for(j=1; j<n; j*=2)
sum=sum+1;
}
}
Difficulty level
This exercise is mostly suitable for students
O(n*log(n)^2)
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Function sorting an array of strings