Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is actually very simple.</p> <p>With <code>(a[i] &gt; a[j]) != (b[i] &gt; b[j])</code>, what we're saying is that this will only be true when the relationship to <code>a[i]</code> and <code>a[j]</code> is the opposite of the relationship from <code>b[i]</code> to <code>b[j]</code>. For this to hold then, if <code>a[i]&gt;a[j]</code> is true, then <code>b[i]&gt;b[j]</code> is false, which means that <code>b[j]&gt;b[i]</code> is true. This means that when <code>a[i]&gt;a[j]</code> is true, <code>b[j]&gt;b[i]</code> is true, and it also means the inverse - when <code>a[j]&gt;a[i]</code> is true, then <code>b[i]&gt;a[j]</code> as well.</p> <p>Another way of saying all of that is <code>( (a[i]&gt;a[j]) &amp;&amp; (b[j]&gt;a[i]) ) || ( (a[j]&gt;a[i]) &amp;&amp; (b[i]&gt;b[j])</code> . That boolean logic will be true only in the same cases where <code>( (a[i] &gt; a[j]) ) != (b[i] &gt; b[j])</code> is true.</p> <p>As another example, consider when both <code>a[i] &gt; a[j]</code> and <code>b[i] &gt; a[j]</code> . You'll see that the first you posted is false in this condition, because the two terms on either side of the <code>!=</code> evaluate to true, meaning the <code>!=</code> evaluates to <code>false</code>. This case also causes the second statement to resolve to false because you don't have either of the two terms around the <code>||</code> evaluating to true, they both evaluate to false.</p> <p>Lastly, this question looks like homework to me - if it is you should use the appropriate tag.</p> <p>However, this all ignores the possibilities of <code>a[i] == a[j]</code> or <code>b[i] == b[j]</code>, which another answer to this question demonstrates can cause the two statements to not evaluate to the same thing. But if you assume that the two cannot be equal, then the two statements from your question will be the same, following the logic demonstrated above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload