Data Structures & AlgorithmsVery hard
Why do the positions of a stable partition by parity keep their relative order, and why is that important?
- A. Partitioning always reverses the order.
- B. Stability only matters for sorting, not partitioning.
- C. A stable partition copies each group in input order, which is required when later steps depend on the original order.
- D. Stable partitions change every value.
Correct answer: C. A stable partition copies each group in input order, which is required when later steps depend on the original order.
Keeping relative order is what distinguishes a stable partition, and it is needed when subsequent logic depends on the original sequence inside each group.
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
- The sorted array [2, 3, 4, 7, 11] contains some positive integers. What is the 5th positive integer that does NOT appear in this array?
- In how many ways can you choose 3 indices from the 9 positions 1 to 9 so that no two chosen positions are adjacent (consecutive integers)?
- What is the length of the longest contiguous subarray of [4, 7, 5, 6, 8, 9, 7, 6, 3, 4] in which the largest value minus the smallest…
- How many contiguous subarrays of [3, 1, 3, 2, 3, 1] have their maximum value occurring EXACTLY twice inside the subarray?
- How many strings of length 5 over the alphabet {a, b, c} contain no two adjacent equal letters when the letter is a or b (two adjacent c's…
- How many binary strings of length 6 have exactly 4 maximal runs (blocks of equal consecutive digits)?