Question: for i = 1 to n { k = 1 while ( k < = n ) { print hello k = k * 2

for i =1 to n {
k =1
while (k <= n){
print hello
k = k *2 Careful!
}
}
a) Show the look bracketing and the number of times each loop is executed.
b) Give the expression T(n) for the number of times hello is printed, in terms of n.
c) How many times will hello be printed if n =1? if n =2? if n =3? Make sure its the correct answer you obtain if you substitute n by each of its 3 values in the expression you have in b).
d) Give T(n) in \Theta notation, in its simplest form.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!