So I was implementing my own binary search tree and noticed that an ugly if statement appears all too often the way I'm doing it (which possibly isn't the best way, but that's not what we're discussing), based on whether a child of a node is the left or right child, e.g:
if (leftChild)
parent.setLeft(child.getRight());
else
parent.setRight(child.getRight());
Then I thought of this:
parent.setChild(childIndex, child.getRight());
Where childIndex is a byte that was determined earlier where leftChild would have been determined.
As you can see this much more concise, but to have it this way I would either have to have an if statement in the setChild method or represent the children as an array of length 2. If we pretend here that this BST requires maximized performance/space efficiency, what kind of trade-off would it be to switch the storage of child node references to a 2-element array, rather than a pair of variables (or even just hide the if statement inside the setChild method).
I know in a real-world situation this might not matter that much, but I'm still interested in which would be the best approach.