14. In an array, how will you find the elements whose sum is "S". Tell all the steps you will do.
1) Sort the array in ascending order.
2) Initialize two index variables to find the 'S'
  elements in the sorted array.
    (a) Initialize first to the leftmost index: l = 0
    (b) Initialize second the rightmost index: r = ar_size-1
3) Loop while l < r.
    (a) If (A[l] A[r] == S) then return 1
    (b) Else if( A[l] A[r] < sum ) then l
    (c) Else r--  Â
4) No 'S' in whole array - return 0
Ram
8 Apr, 2018 8:48 PM
1) Sort the array in ascending order.
2) Initialize two index variables to find the 'S'
  elements in the sorted array.
    (a) Initialize first to the leftmost index: l = 0
    (b) Initialize second the rightmost index: r = ar_size-1
3) Loop while l < r.
    (a) If (A[l] A[r] == S) then return 1
    (b) Else if( A[l] A[r] < sum ) then l
    (c) Else r--  Â
4) No 'S' in whole array - return 0
Report Error
Report Error
Please Login First Click Here