Java – the difference between Max heap and sort stack
•
Java
I want to know when we can use collections Why do we need a new data structure like Max heap when sort method sorts the stack? thank you
Solution
Stack and heap have completely different properties and usage
@H_ 403_ 12@
LIFO needs to be stacked Sorting it will cost o (n * logn) and push / bounce o (1)@ H_ 403_ 12@
For example, the priority queue needs a heap. It will take o (1) to get the minimum / maximum element and insert the element o (log (n)) @ H_ 403_ 12@
You need to identify usage patterns and goals, and then determine what you need@ H_ 403_ 12@
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码