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?
- A. 3
- B. 2
- C. 1
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- What is the edit distance (insert, delete, substitute; each cost 1) between MATRIX and STRATEGY?
- A B-tree has minimum degree t = 3 (every non-root node has between 2 and 5 keys) and height 3 (a root-only tree has height 0). What are…
- How many subsets of {1, 4, 8, 9, 10, 11, 12} have sum exactly 27?
- What is the maximum flow from S to T in the network with directed capacities A→B (15), A→C (9), A→T (12), B→T (12), C→B (12), S→A (6), S→B…
- An undirected graph has edges A–B, A–D, B–H, C–D, C–F, C–G, D–G, E–F, E–H, F–G. BFS starts at A and always scans neighbours in…
- A binary tree with distinct labels has INORDER G D C I F A B H E and LEVEL-ORDER E A D H G I B C F. What is its postorder traversal?