Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,

I am asked to write in pseudocode a Θ(n)-time algorithm in recursive form that, given a set S of
n integers, determines which two elements in S have the largest sum.

Can anyone help me with this problem and explain how you can show the actual running time by solving the recurrence ?

Thank you

What I have tried:

I am able to write an algorithm if the set is sorted, but I am not allowed to use a sorted array as this would be Θ(n log n)-time
Posted
Updated 14-Mar-16 6:56am
Comments
Dave Kreskowiak 14-Mar-16 12:28pm    
You're going to have to show the code you've written. Nobody is going to do the work for you.
Matt T Heffron 14-Mar-16 13:18pm    
Isn't that just the two largest elements?
That should be trivial.

1 solution

O(n) means you will go through each element, so if you have 10 elements you will go through all 10 elements once to get your results.

With that comment you should be able to do your homework.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900