Implementing a binary heap using a linked list [duplicate]

谁说胖子不能爱 提交于 2019-12-25 09:28:09

问题


Possible Duplicate:
Linked list implementation of Binary Min Heap (Having trouble with manipulation…)

Greetings,

I'm having trouble figuring out an algorithm that will give me the location of a tree node in a linked list implementation of a binary heap. I've implemented a heap using arrays now I want to try using a linked list; Is there a way to find the tree node whose array index would have been i had I used an array to represent the heap?


回答1:


take a look at Michael Springmann implementation




回答2:


What's the point? A linked list implementation will be either slower or more complex than an array-based one. If you replace the array with a simple linked list and don't add other structure your insertion time will be O(n) instead of O(log n), and then you could as well just maintain a sorted list in same O(n) complexity.



来源:https://stackoverflow.com/questions/5609700/implementing-a-binary-heap-using-a-linked-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!