Technical Question: Implement a priority queue
Anonym
My first approach was to implement this using a list as the underlying data structure, basically brute force, get the min idx each time and pop that index of the array... Every insert just appends, which worst case is maybe O(N) if python has to reallocate a larger array and copy over elements. Every pop worst case is also O(N) where n is number of elements in list. Then implemented it using a linked list, which gave worst case insert of O(n) in the case where the entire list must be traversed. However, this gave constant time popping, which is always pop off head node, replace head, and return popped node. List is kept sorted. He mentioned (at the end) using a min heap binary tree, which would give O(log n) insert and O(log n) pop. I will self evaluate to C+ on this one.