Question

Given an array of numbers, you want to find out the three greatest numbers. Do you...

Given an array of numbers, you want to find out the three greatest numbers. Do you have to sort the array, or is there a faster way than applying a sorting algorithm? Explain why you use or not use sorting in terms of the worst-case running time. Give an example.

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

=>There's no need to use sorting any algorithm for finding the greatest numbers. Because we may use three variables name Max1,Max 2,Max3.

=>while traversing the array we'll update the three variables If needed otherwise go for next index element.

=> This method takes O(n) time but any sorting Algorithm takes at least O(n logn)time so the O(n) method is efficient.

Ex : A={1,2,3,4,5,6,7,8,9,10,11,12,13}

Max 1 = 13

Max 2 = 12

Max 3 = 11

After iterations... If sorting it takes O(13 log 13) but the actual method takes O(13)

Add a comment
Know the answer?
Add Answer to:
Given an array of numbers, you want to find out the three greatest numbers. Do you...
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