Let p x 1 , . . . , p x n be the number of structure elements in the first sequence Seq x and p y 1 , . . . , p y m be the number of structure elements in the second sequence Seq y . Each structure element has a left and right endpoint in the sequence and is a stem, interrupted stem, multiloop or H-type pseudoknot. Structure elements can also be represented as nodes in a graph. In each sequence, the structure elements are ordered by their right endpoints. An edge is drawn between two structure elements in the first and the second sequence if their base pair similarity score has a P-value less than . Given the set of edges between nodes p x 1 , . . . , p x n and p y 1 , . . . , p y m , the goal is to find the set of edges with maximum weight that are non-crossing. This relates to finding the set of non-overlapping structure elements in the two sequences that maximize the score under the requirement that the interval ordering is preserved. A set of structure elements in the first and second sequence, which preserves the interval ordering is called a feasible structure element alignment and must satisfy the following two requirements. Each structure element can be aligned with at most one other structure element in the other sequence. The order of structure elements must be preserved with respect to the alignment. That is, if structure elements p x i and p x j in the first sequence are aligned with p y a and p y b in the second sequence, respectively, the pairs may never overlap: p x i 5p x j^p x a 5p x b (Fig. 2) . Given nodes p x 1 . . . , p x n in the first sequence Seq x and p y 1 , . . . , p y m in the second sequence Seq y , let f(i, a) be the maximum sum of edge weights for nodes between 1 and i in the first sequence and 1 and a in the second sequence such that the edges are non-crossing (i n and a m). The nodes that maximize the sum of edge weights are called an optimal structure element alignment for the two sequences. The optimal structure element alignment is calculated using dynamic programming. For a given structure element p i with start point a i and end point b i , let pre(i) be the non-overlapping predecessor. For each structure element, its predecessor is pre-computed using the sorted list of structure elements. The recursion for calculating the optimal structure element alignment is as follows: