GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A 4-input comparator network applies, in order, the comparators (0,1), (2,3), (0,2), (1,3), (1,2), each putting the smaller value on the lower-indexed wire. It sorts all inputs. If the last comparator (1,2) is removed, how many of the 24 permutations of 4 distinct keys does the shortened network still sort?
- A. 12
- B. 8
- C. 16
- D. 6
Correct answer: B. 8
After the first four comparators the minimum is on wire 0 and the maximum on wire 3; only wires 1 and 2 may still be out of order. Simulating all 24 permutations, the middle pair is already in order for 8 of them. (By the 0-1 principle, 4 of the 16 binary inputs fail without (1,2).)
More Algorithms questions
- How many comparators does Batcher's bitonic sorting network for 16 inputs use?
- Which is the tight solution of T(n) = 3T(n/4) + n^(log₄3)·log₂ n?
- Solve T(n) = 2T(√n) + log₂ n for large n. Which is the tight bound?
- Let T(n) = T(n − ⌊√n⌋) + 1 for n > 1 and T(1) = 0. Which is the tight bound?
- Let T(n) = T(n/2) + n(2 − cos n) (n in radians) with T(1) = 1. Which statement about T(n) is correct?
- How many times does x++ execute? for (i = 1; i <= 64; i = 2) for (j = 1; j <= i; j++) for (k = j; k <= i; k = 2) x++;