Union Data Structure and greedy hanmming clustering