A support system must select the request with the highest urgency score. If several requests share that score, it must select the one with the smallest request identifier. Scores are whole numbers, identifiers are unique positive integers, and records arrive in no guaranteed order.
The original algorithm keeps a candidate and checks every remaining record. It replaces the candidate when the new record has a higher score, or when scores are equal and the new record has a smaller identifier.
A proposed shortcut skips a record whenever its score is less than or equal to the current candidate's score, without checking its identifier. Which assessment is correct?
The shortcut is safe because unique request identifiers prevent ties between urgency scores.
The shortcut is safe because it preserves the highest urgency score found during the scan.
The shortcut is unsafe because an equal-score record may have a smaller request identifier.
The shortcut is unsafe because changing the candidate requires checking every earlier record again.
Unlock full course notes by signing up
Repairing a stalled processing loop
An algorithm processes a finite, nonempty queue of expense claims. Its position starts at the first claim, and the queue does not change during processing. The instructions repeat while the position refers to a claim:
If required information is missing, record REVIEW and immediately restart the loop at the current position.
Otherwise, record the policy outcome and advance the position to the next claim.
Tracking current and longest failure streaks
A payment gateway monitors consecutive validation failures. Its state consists of the values carried from one record to the next: the current failure streak and the longest failure streak seen so far.
Both values start at zero. For each record, the algorithm performs these updates in order:
If the result is Fail, increase the current streak by one. If the result is Pass, reset the current streak to zero.
Designing tests for overlapping inventory rules
A retailer classifies inventory records using stock in whole units, supplier lead time in whole days, and a frozen-account flag. Stock is a nonnegative integer or missing; lead time is a positive integer or missing; the flag is always available.
The required policy is:
A missing stock or lead-time value produces REVIEW.
How arrival order changes comparison costs
A registration audit processes eight records. The client identifiers are 114, 208, 351 and 476, with each identifier appearing exactly twice. The records may arrive in any order.
For each incoming record, the algorithm scans all previously processed records from earliest to latest. Each equality check between two identifiers contributes one to the operation count, the total number of checks performed.
The scan stops at the first matching identifier or after checking every previous record. When a match is found, only the inner scan stops; processing continues with the remaining incoming records. After its scan, every incoming record is appended to the processed list, including duplicates. The first record requires no comparisons.