How does a greedy algorithm work in H-DA sorting?