0

I'm trying to write a binary heap implemented over a binary tree, but I'm having trouble finding a way to add a new node to the "bottom" of the heap, i.e. the first null space on the tree in a breadth-first traversal. I've already got a working heapify function, but I can't figure out how to add a new node before heapifying.

I can't seem to think of a consistent algorithm that can find the null space that I can add my node to, every time I think I come up with something, it doesn't work. What do I do?

Zong
  • 6,160
  • 5
  • 32
  • 46
user2309750
  • 1,403
  • 4
  • 14
  • 11
  • Related: http://stackoverflow.com/questions/14780152/how-to-insert-into-a-binary-max-heap-implemented-as-a-binary-tree/14780554#14780554 – templatetypedef Apr 25 '13 at 05:19
  • possible duplicate of [Adding an element to the first non-occupied leaf in a binary tree](http://stackoverflow.com/questions/16204556/adding-an-element-to-the-first-non-occupied-leaf-in-a-binary-tree) – Pratik Apr 25 '13 at 12:53

0 Answers0