Data Structures & AlgorithmsVery hardGATE CS

The boolean expression T ^ T | T ^ F (T = true, F = false, & = AND, | = OR, ^ = XOR) can be fully parenthesised in 5 ways. In how many of them does it evaluate to true?

  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 4

Correct answer: B. 2

Split at each operator and combine (true, false) counts of the two sides: & needs both true, | fails only if both false, ^ needs them to differ. The full expression gives 2 true and 3 false out of 5.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic