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.
最大 1 つのスワップでヒープへの挿入を実行するアルゴリズムはありますか (O(log n) の比較が許可されます)
いいえ。
このヒープを考えてみましょう:
200 を追加するとします。明らかに、それが新しいルートになる必要があります。
では、100 はどこに行くのでしょうか。3 の子になることはできません。これは、スワップが 1 つしかない場合に行う必要があることです。