Implementing branch and bound algorithm