Right now I'm trying to write a binary heap in Java implemented over a binary tree structure, and while I do have a very good grasp on how to "heapify" the tree after adding an element, the logic for finding the first unoccupied leaf at the bottom of the heap eludes me.
I'm aware that finding the first unoccupied leaf is supposed to be a breadth-first traversal, but I still can't figure out how exactly a breadth-first traversal algorithm would work.