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.
您如何跟踪插入堆的位置:我认为使用检查每个子树高度的函数会将算法从 O(log N) 降级为 O(N)。
因此,您是在每个节点中保留一个变量,还是在具有最后一个插入点的堆中保留一个变量(如何定义?)。
堆是“几乎满的”二叉树。所以你只有一个选择,你应该在哪里插入新元素,不需要高度检查——但是一个指向下一个元素应该插入的位置的指针。这当然足以确保 O(logn) 的高度