Question

CODE: (For i ← 1 to (1.5×n) do indent: print i (For i ←1 to n...

CODE:

(For i ← 1 to (1.5×n) do

indent: print i

(For i ←1 to n do

indent: print n+1-i

A. What is the output for the following values of n? N = 2 , N = 4, N=6

B. What is the time complexity of this algorithm? Assume that n is an even natural number.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
A.
When N = 2
Output is
1 2 3 2 1

When N = 4
Output is
1 2 3 4 5 6 4 3 2 1

When N = 6
Output is
1 2 3 4 5 6 7 8 9 6 5 4 3 2 1

===========================

B.
Assume that n is an even natural number.
Time complexity of this algorithm
= O(1.5*n) + O(n)
= O(2.5*n)
= O(n)
Add a comment
Know the answer?
Add Answer to:
CODE: (For i ← 1 to (1.5×n) do indent: print i (For i ←1 to n...
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