Question

Analyze the operation performed by the given piece of pseudocode and write a function that describes...

Analyze the operation performed by the given piece of pseudocode and write a function that describes the number of steps required. Give the \Theta-class of the function

Assume that N is a power of 2.

1. X \leftarrow 1

2. K \leftarrow N

3. WHILE (K \geq 1)

a. X \leftarrow 3X

b. K \leftarrow \left \lfloor K/2 \right \rfloor

0 0
Add a comment Improve this question Transcribed image text
Answer #1

We are given that N is power of 2 and in while loop each time we are dividing K=K/2, in this way for any value of N while loop will be executed by Sqrt(N) +1 number of times. For example,

N = 16

1. After first iteration K = 16/2 = 8

2. After second iteration K = 8/2 = 4

3. After third iteration K = 4/2 =2

4. After fourth iteration k = 2/2 =1, now this will be the last iteration beacuse now K is 1.

So loop will be executed 5 times = 4 ( because 16 is 4th power of 2 ) +1

Running time = \Theta (\sqrt{N})

Add a comment
Know the answer?
Add Answer to:
Analyze the operation performed by the given piece of pseudocode and write a function that describes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT