Question

Algorithm 1 CS317FinalAlgorithm (A[O..n-1]) ito while i<n - 2 do if A[i]A[i+1] > A[i+2) then return i it i+1 return -1

Using the pseudocode answer these questions

6. Use limits to show that, for best case inputs, the asymptotic growth of the number of comparisons is (1). Show your work.

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

6)

In the best case, the comparison is done only 1 time

that is when A[0]A[1]> A[2]

we will return 0 in the best case as the value of i =0

1= Θ(1)

c1*1<= 1 <= c2*1

where c1= 0.5 and c2= 1

7)

as discussed in the worst case we take n-2 comparisons

n-2 = Θ(n) because

c1*n<= n-2 <= c2n

where c1= 0.5 and c2= 1 for all n>=10

Add a comment
Know the answer?
Add Answer to:
Using the pseudocode answer these questions Algorithm 1 CS317FinalAlgorithm (A[O..n-1]) ito while i<n - 2 do...
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
ADVERTISEMENT