Phalkey i tried solving it with tree method but its very tedious, why don't you follow this approach, its best approach for questions like this https://gateoverflow.in/8060/gate2015-2-11
64.3k questions
77.9k answers
243k comments
79.6k users