create minheap within the algo rather than pass it