Read abstract values from different encodings

A monitoring component stores the set of active sensors among sensor IDs 101, 102, 103 and 104. Its public operations are countActive(), which returns the number of active sensors, and isActive(id), which returns whether the specified sensor is active.


Two internal encodings are supported:

  • Flags: four entries correspond, in order, to IDs 101, 102, 103 and 104. An entry of 1 means active; 0 means inactive.
  • ID list: each active sensor ID appears exactly once. An empty list contains no active sensors.

Each table row describes an independent state. Complete the public observations using exact integers for counts and yes or no for membership.

EncodingStored datacountActive()isActive(103)
Flags1, 0, 1, 0
ID list101, 104
ID listEmpty list
Flags0, 1, 1, 1

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Procedural and Data Abstraction Questions: