Data Structures & AlgorithmsVery hard

Why can the number of distinct OR values over all subarrays of an array be small even for long arrays?

  1. A. OR always returns zero for long arrays.
  2. B. OR values are always powers of two.
  3. C. Each new element only adds bits, so the OR values ending at a position form a short chain of growing numbers with few changes.
  4. D. Repeated OR values are removed automatically by the hardware.

Correct answer: C. Each new element only adds bits, so the OR values ending at a position form a short chain of growing numbers with few changes.

The distinct ORs ending at any right end form a monotone chain where each step adds bits, so there are at most about log(max value) of them. The total number of distinct OR values stays small.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic