Works for the General case where num of nodes is not a power of 2