7. Assume first that =0Then []+[]=0if and only if []=−[]
i.e., these two elements have the same absolute value but opposite signs.
Wecancheckforpresenceofsuchelementsinagivenarrayinseveraldif–
ferent ways. If all the elements are known to be distinct, we can simply
The case of an arbitrary value of isreducedtothecaseof=0by the fol–
lowing substitution: []+[]=if and only if ([]−2)+([]−2) =
0In other words, we can start the algorithm by subtracting 2from
each element and then proceed as described above.
8. Sort all the ’s and ’s by a (log )algorithm in a single nondecreas-
ing list, treating as if it were smaller than in case of the tie =
Scan the list left to right computing the running difference between
the number of ’s and ’s seen so far. In other words, initialize to 0