Data Structures and Algorithms
Last updated
Was this helpful?
Last updated
Was this helpful?
Priority Queue: Tips on when to choose priority queue as the data structure: Ref:
Event-driven simulation: customers in a line, colliding particles
Numerical computation: reducing roundoff error
Data compression. Huffman codes which compresses data.
Graph searching: Dijkstra's algorithm, Prim's algorithm
Number theory: sum of powers
Artificial intelligence: A* search
Statistics: maintain largest M values in a sequence
Operating systems: load balancing, interrupt handling Discrete optimization. bin packing, scheduling Spam filtering. Bayesian spam filter
Finding top items: N busiest network connections, N most valuable customers, N largest disk users
We typically use BFS orDFS search to explore graphs. BFS uses a Queue() data structure to store all the neighboring nodes and explores them in a FIFO order. DFS on the other hand uses a Stack() data structure to go deeper to store all the nodes and then explore them in a LIFO order.
In Dijkstra or in A* search this needs to change.
The Graph now needs to know the the cost of selecting the next node.
We cannot use simple Queue any more, since we have to associate some kind of priority to each of the neighboring nodes and pick the next node based on that priority. So we change our data structure choice from Queue() to priority queue()
The search now needs to figure out this cost and build the priority queue based on this information