implemented merge pairs algorithm

based on a range based tree