I have an XML file with the following structure:
<block1>
<node>
<name>A<name/>
<node/>
<node>
<name>B<name/>
<node/>
...
</block1>
<block2>
<node>
<name>B<name/>
<node/>
<node>
<name>D<name/>
<node/>
...
</block2>
The entrees of each block are sorted based on the name.
I want to create a table that will hold all of the names that belong in block1 and block2.
How can I do this efficiently (using the fact that the nodes are sorted)?
A solution using keys:
When this transformation is applied on the (corrected from severe malformedness) provided XML document:
the wanted, correct result is produced:
The efficiency of this solution is O(k), where
kis the number of distinct values in Set 1. This assumes that we have already constructed the keys (indexes) and the set of distinct values in Set 1.