priority queues with binary heaps in earlier sections you learned about the first-in first-out data structure called queue one important variation of queue is called priority queue priority queue acts like queue in that you dequeue an item by removing it from the front howeverin priority queue the logical order of items inside queue is determined by their priority the highest priority items are at the front of the queue and the lowest priority items are at the back thus when you enqueue an item on priority queuethe new item may move all the way to the front we will see that the priority queue is useful data structure for some of the graph algorithms we will study in the next you can probably think of couple of easy ways to implement priority queue using sorting functions and lists howeverinserting into list is (nand sorting list is ( log nwe can do better the classic way to implement priority queue is using data structure called binary heap binary heap will allow us both enqueue and dequeue items in (log nthe binary heap is interesting to study because when we diagram the heap it looks lot like treebut when we implement it we use only single list as an internal representation the binary heap has two common variationsthe min heapin which the smallest key is always at the frontand the max heapin which the largest key value is always at the front in this section we will implement the min heap we leave max heap implementation as an exercise binary heap operations the basic operations we will implement for our binary heap are as followsbinaryheap(creates newemptybinary heap insert(kadds new item to the heap find_min(returns the item with the minimum key valueleaving item in the heap del_min(returns the item with the minimum key valueremoving the item from the heap is_empty(returns true if the heap is emptyfalse otherwise size(returns the number of items in the heap build_heap(listbuilds new heap from list of keys the code below demonstrates the use of some of the binary heap methods notice that no matter the order that we add items to the heapthe smallest is removed each time we will now turn our attention to creating an implementation for this idea import binheap bh binheap(bh insert( bh insert( bh insert( bh insert( as defined below trees and tree algorithms