You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After sorting of S, a search of two a, b in S such that a + b = x can be improved.
FIND-SUM(S, x) // Indexes in S are 1, 2, ..., n
S = SORT(S)
i = 1
j = n
while i < j
sum = S[i] + S[j]
if sum == x
return TRUE
if sum < x
i = i + 1
else
j = j - 1
return FALSE
Using this way, the time complexity of the search is Θ(n) instead of Θ(n lgn). (But, it's obviously that time complexity of entire algorithm stays same.)
The text was updated successfully, but these errors were encountered:
After sorting of S, a search of two a, b in S such that a + b = x can be improved.
Using this way, the time complexity of the search is Θ(n) instead of Θ(n lgn). (But, it's obviously that time complexity of entire algorithm stays same.)
The text was updated successfully, but these errors were encountered: