building logic behind decision tree