Heap and Priority Queues Algoritm