Can someone explain this to me? Such as this:
Given a function:
for k = 1 to lg(n) for j = 1 to n x=x+1
How would I analyze the tight (Θ) bound?
Can someone explain this to me? Such as this:
Given a function:
for k = 1 to lg(n) for j = 1 to n x=x+1
How would I analyze the tight (Θ) bound?
Your function is Θ(log n · n): The outer loop is repeated log n times and the inner loop n times (for each iteration of the outer for
), so x=x+1
is executed log n · n times in total. And since the number of repetitions is fixed, the lower and upper bound is the same.