Question

(5 marks) Algorithm performance Explain a) (4 marks) Give the order of magnitude e Ofor the following algorithm. why your answer is correct. GET VALUES for A1, A2, ...3 An, and B1, B Bn Get value of n set i equal to 1 i 1 for each of the n values in A DO WHILE (is n) set j equal to 1 i 1 DO WHILE G S n) Do n times IF Ai Bj THEN PRINT Found it! increment j j j+1 END DO WHILE increment i END DO WHILE (1 mark) Explain what the algorithm does.

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

For each value of A, it is searching in B. So basically this algorithm finding the comman elements.

Here we have two do while loop. One is nested in other.

Since size of A and B is n.

So, T(n) = 1 + 2+ 3+ ...+n = n(n+1)/2 = O(n^2)

Add a comment
Know the answer?
Add Answer to:
Algorithm performance Give the order of magnitude Theta () for the following algorithm. Explain why your...
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