Let be the oriented nodes in in increasing left endpoint order (we ignore unoriented nodes at this stage). To locate a happy clique in , the algorithm traverses the oriented nodes in according to this order. Let L(e) and R(e) be the left and right endpoints, respectively, of the interval corresponding to a node e in the realization of . After traversing for , the algorithm maintains a happy clique Ci in the subgraph of induced by these vertices. Assume |Ci|=j, and let be the vertices in Ciwhere . The vertices of Ci are maintained in a linked list ordered in increasing left endpoint order. If there exists an interval that contains all the intervals in Ci then the algorithm maintains a minimal such interval ti. The clique Ci and the node ti (if exists) satisfy the following invariant:
We prove the correctness of this invariant by induction: Initially
and t1 is undefined. If
R(nij) < L(ni+1)then Ci is guaranteed to be happy in
(see figure
10.12(a)), therefore we need to focus only on cases with
.
The induction step: We assume
correctness up until i and show how to obtain Ci+1 and
ti+1 if
.
We
have to consider the following cases:
Case 1. The
interval ti is defined and
R(ti) <R(ni+1). Continue with
Ci+1 = Ci and
ti+1 = ti. See figure
10.12(b).
Case 2. The interval
ti is not defined or
.
a)
R(nij) < R(ni+1) and
.
Ci+1 is obtained by adding ni+1 to Ci and
ti+1 =
ti. See figure 10.12(c).
b)
R(nij) < R(ni+1) and
L(ni+1) > R(ni1).
The clique Ci+1consists of vi+1 alone and
ti+1 = ti. See figure
10.12(d).
c)
R(ni+1) < R(nij). As in the previous case
.
In this case ti+1 is set to nij,
the last interval in Ci. See figure 10.12(e).
The fact that Ci is happy in the subgraph induced by follows from this invariant. It is straightforward to see that the clique Clthat the algorithm stops with, is happy.
The running time of the algorithm is proportional to the number of oriented nodes traversed since a constant amount of work is performed for each oriented node it encounters.