Binary tree lookup algorithm