hi ppl!

i would like to know how to use a binary search tree to find the optimal double base representation of a decimal number
for eg with bases 2 n 3
200=(2^7)*3
75=(2*(3^3))+((2^2)*3)+((2^0)*(3^2))

my algorithm to find the optimal double base representation of a number N using recursion is:
step 1 : find the highest power combination, C, of 2 & 3 which is closest to N
step 2 : subtract C from N to get a difference D
step 3 : repeat step 1 with D inplace of N

my question is how can i use a binary tree/binary search with this algoritm..
i just need the theory(ie "funda") behind it...the code ill write myself..

thanks for readin!