Implement greedy matching algorithm