- #1
mathmari
Gold Member
MHB
- 5,049
- 7
Hey!
Let $S$ be a set of $n$ integers. Assume you can perform only addition of elements of $S$ and comparisons between sums. Under these conditions how many comparisons are required to find the maximum element of $S$?
I thought that we could find the maximum element as followed:
That means that $n-1$ comparisons are required.
Is this correct?? (Wondering)
Let $S$ be a set of $n$ integers. Assume you can perform only addition of elements of $S$ and comparisons between sums. Under these conditions how many comparisons are required to find the maximum element of $S$?
I thought that we could find the maximum element as followed:
Code:
max=S(1)+S(1)
k=1
for j=2 to n
sum=S(1)+S(j)
if sum>max
max=sum
k=j
return S(k)
That means that $n-1$ comparisons are required.
Is this correct?? (Wondering)