using a tree for k way merge