The standard three-case master theorem concernswith constant base-case cost and eventually nonnegative . Put .
- If for some , then .
- If , then .
- If for some and eventually for a constant , then .
In a divide-and-conquer algorithm, counts recursive subproblems, is their size, and accounts for splitting and combining. The comparison with identifies whether leaves, all levels, or the upper levels dominate the running time. The polynomial gap and the third case's regularity condition are part of this version of the theorem.
Build a balanced comparison tournament, retaining the record of each value's direct defeats. A record stores a key and a list of records that it directly defeated:There is one key comparison at each merge. Because is a set, all keys are distinct, so the greater winner is unambiguous. Retaining the losing record also retains its own earlier comparison history; it does not merely retain the losing root's value.
tournament(S):
if |S| = 1:
return Node(the element of S, [])
split S into equally sized L and R
a = tournament(L)
b = tournament(R)
if a.key < b.key:
exchange a and b
prepend b to a.losers
return aLet the returned root have value . DefineThe second-largest value can only lose to , so it occurs among those direct losers. This proves the required partition and the exclusion of the second-largest value from the third part. For , the winner participates in exactly merges, so . The other part can be materialized by marking the original element identities in this list and scanning the original inputs, using additional operations without more comparisons between keys.
The first value is the tournament winner . Find the second value by taking the maximum of the direct-loser set , retaining its associated tournament record.
The third-largest value must have lost directly to either or : any other value is smaller and could not defeat it. Therefore it belongs toConversely, every value in is distinct from . Thus the third-largest value is . This is tournament selection of the three largest elements; it uses the retained defeat records while computing the requested three-part partition.
Three largest elements exist only for . With the paper's power-of-two assumption this means . The partition in part (b) remains meaningful for , but a third output cannot be supplied in that case.
The balanced comparison tournament usesso . The second-largest search compares direct losers, using comparisons. The record of contains at most direct losers, because loses before becoming the overall winner. Hence the third candidate set has size at most , requiring at most comparisons.
For , the complete comparison count is thereforeThis is and therefore meets the requested bound. The defeat-record lists can be linked in constant local work per merge; flattening the final partition takes work. Thus the method also has linear overall running time under constant-cost key comparisons.
Articles by others on the same topic
There are currently no matching articles.