Data Structures & AlgorithmsVery hard
Which property makes the ordered-pair count of A[i] > A[j] equal to the number of unequal unordered pairs?
- A. Every pair of equal values also satisfies the inequality.
- B. For each unequal unordered pair exactly one ordering has the larger value first, so the ordered count with strict inequality equals the number of unequal unordered pairs.
- C. The inequality holds for both orders of every pair.
- D. The count is always zero.
Correct answer: B. For each unequal unordered pair exactly one ordering has the larger value first, so the ordered count with strict inequality equals the number of unequal unordered pairs.
Among the two orderings of an unequal pair only one satisfies A[i] > A[j], so the strict count equals the unequal pairs. Equal pairs satisfy neither ordering, which is why the two counts match.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- When an array's values are all distinct, what is the number of ordered pairs (i, j), i ≠ j, with A[i] > A[j]?
- Push and pop operations on an initially empty stack are: push, push, pop, push, push, push, pop, pop, push. What is the maximum height the…
- Customers arrive at times 0, 1, 2 and 5 and need service times 3, 2, 1 and 2 on a single server (first come, first served; a customer…
- For the same four customers (arrivals 0, 1, 2, 5; service times 3, 2, 1, 2) on a single first-come-first-served server, what is the…
- A list holds 1 to 9 in order. The first 4 nodes are reversed, then the node with value 6 is deleted. What is the value at position 5 of…
- How many contiguous subarrays of [1, 2, -3, 3, -3, 2, 1] have sum exactly zero?