| CPSC 320: Analysis of Algorithms | Spring 2026 |
(a) Prove that $T = T'$.
(b) Prove that $T = T'$ is false with a minimal counterexample with the least number of nodes.
If it was discovered that a student $s$ was already infected at time $t$, could it possibly have put another student $s'$ at a high risk of being infected by time $t'$?Clearly, if $s$ and $s'$ were in the same class between $t$ and $t'$, then it would immediately put $s'$ at a high risk. However, even if $s$ and $s'$ were never in the same class, $s'$ could be put at a high risk through a sequence of pairs of other classmates all of whom had been identified to be at a high risk, originally caused by $s$'s infection. For example, for $n = 4$ and $m = 5$, consider the trace data consisting of: $$ (s_1, s_2, 8), (s_2, s_4, 9), (s_3, s_4, 9), (s_1, s_4, 11), (s_1, s_3, 12) $$ If it was discovered that $s_1$ was infected at 7, then $s_3$ would be at a high risk by 9, through $s_2$ and $s_4$ (although $s_1$ and $s_3$ were not in the same class until 12). On the other hand, if it was discovered that $s_2$ was infected at 10, then $s_3$ would not be at a high risk by 12 (in fact, no one else would be at a high risk anytime). Design an $O(n + m)$-time algorithm to answer, given such a sequence of trace data, the above yes/no question; that is, given students $s$ and $s'$ and times $t$ and $t'$, whether or not $s$ being infected at $t$ could put $s'$ at a high risk of being infected by time $t'$.
|
|
CPSC 320 home page |
|
|