Tuesday, 15 January 2013

java - Why use heap instead of binary tree when implementing priority queue? -


It seems that the only advantage of a heap on a binary tree is to find the smallest object in the stack in the complexity of o (1) binary In the tree o (log (2) instead of n (1).

When applying the priority queue you will need to delete the smallest item of each from the data structure. The complexity of the two stacks (log (2) N). The removal of obesity from a tree can be more complex .

My question is, use the heap rather than binary tree (which is simple in this case) when applying the priority queue?

Binary Tree Matters The worst case complexity will be o (n) when the binary tree is converted into an array whereas it remains oh in the heap (log). You can use a balanced binary tree like red hair or avel, but then It becomes more complex and more memory Required.

No comments:

Post a Comment