0

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

Jay
  • 1
  • 1

1 Answers1

1

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.

harold
  • 61,398
  • 6
  • 86
  • 164