Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: Binary Min Heap 的链表实现(操作有问题……)
问候,
我无法找出一种算法,该算法将为我提供二叉堆的链表实现中树节点的位置。我已经使用数组实现了一个堆,现在我想尝试使用链表;如果我使用数组来表示堆,有没有办法找到其数组索引的树节点?
重点是什么?链表实现将比基于数组的实现更慢或更复杂。如果你用一个简单的链表替换数组并且不添加其他结构,你的插入时间将是 O(n) 而不是 O(log n),那么你也可以在相同的 O(n ) 复杂性。
看看Michael Springmann 的实现