Arrays & Linked Lists



Answer & solution
Answer: n−1. (no official key was published)
The first input node is taken as the initial retained node t1. Before the loop, t2 is set to the second input node. The loop then advances t2 exactly once through every remaining original node, stopping at NULL. Since there are n−1 nodes after the first, S1 is evaluated exactly n−1 times.
Rewiring t1->next inside S2 does not skip any as-yet unvisited node. When S2 executes, t1 is moved to the current t2, but that current node's own next pointer has not been changed. The subsequent t2=t2->next therefore advances to its original successor. When S2 does not execute, t1 remains the retained node and the same successor step still happens. Thus all-equal and all-distinct lists perform the same number of value comparisons.
For example, on [1,1,2,2], S1 compares the second 1, first 2, and second 2 against the current retained value, for three comparisons. The while-condition test is a different comparison and is not included in this count.
This leaf uses the full shared stem and belongs to that single group; it is not evidence for an extra exam question. The displayed code restores legal pointer-member notation while retaining its algorithmic operations.