@Axoren Could we prove like that the time complexity?
$D$ contains n elements, so the time complexity of Heapsort(D) is O(n*lgn).$E$ contains m elements, so the time complexity of Heapsort(E) is O(m*lgm). The while-loop is executed at most n times and the time-complexity of binary_search is O(lgm), so the time-complexity of the while-loop is O(n*lgm). Then the time complexity of the if and else statement is O(1).
In total, the time complexity of the algorith is $O(n \cdot lgn+m \cdot lgn+n \cdot lgm)=O((n+m) \cdot lgn+n\cdot lgn) \leq O((n+m) \cdot \lg(n+m)+(n+m) \cdoot \lg(n+m))=O((n+m) \c…