Jay
Jay

Reputation: 1

Insertions into a max heap with atmost one swap

Is there a algorithm to perform insertions into a heap with atmost one swap (O(log n) comparisons are allowed)

Upvotes: 0

Views: 90

Answers (1)

user555045
user555045

Reputation: 64904

No.

Consider this heap:

max heap

Suppose you add 200. Obviously it will have to become the new root.

So where does 100 go? It can't become a child of 3, and that's what it would have to do if you only have one swap.

Upvotes: 1

Related Questions