A Novel Algorithm to solve N-Queens and Sum of Subset Problems