Count condition tests in an inventory scan

A warehouse program searches the following inventory records in increasing index order. Each request starts a fresh sequential search at index 0.


Index

Code

Units available

0

PX

0

1

QJ

5

2

PX

3

3

MN

7

4

PX

6


The program uses short-circuit evaluation: it first tests whether the record's code equals the requested code, and it tests the quantity only when the code matches. The quantity test checks whether available units are greater than or equal to the requested minimum. The search stops at the first record passing both tests, or after the last record if none qualifies.


A decision diagram shows the code test followed conditionally by the quantity test for each inspected record.


Complete the table with the exact integer number of code tests and quantity tests executed for each request. Count only these two kinds of test; ignore loop-control tests.

Requested codeMinimum unitsCode testsQuantity tests
PX4
QJ6
MN2
XZ1

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 Sequential Search Questions: