Found 13 Articles for Backtracking Algorithms

N Queen Problem

Sharon Christine
Updated on 16-Jun-2020 07:51:36

13K+ Views

This problem is to find an arrangement of N queens on a chess board, such that no queen can attack any other queens on the board.The chess queens can attack in any direction as horizontal, vertical, horizontal and diagonal way.A binary matrix is used to display the positions of N Queens, where no queens can attack other queens.Input and OutputInput: The size of a chess board. Generally, it is 8. as (8 x 8 is the size of a normal chess board.) Output: The matrix that represents in which row and column the N Queens can be placed. If the ... Read More

M-Coloring Problem

karthikeya Boyini
Updated on 16-Jun-2020 07:58:12

8K+ Views

In this problem, an undirected graph is given. There is also provided m colors. The problem is to find if it is possible to assign nodes with m different colors, such that no two adjacent vertices of the graph are of the same colors. If the solution exists, then display which color is assigned on which vertex.Starting from vertex 0, we will try to assign colors one by one to different nodes. But before assigning, we have to check whether the color is safe or not. A color is not safe whether adjacent vertices are containing the same color.Input and ... Read More

Hamiltonian Cycle

Sharon Christine
Updated on 07-Nov-2023 20:21:18

25K+ Views

In an undirected graph, the Hamiltonian path is a path, that visits each vertex exactly once, and the Hamiltonian cycle or circuit is a Hamiltonian path, that there is an edge from the last vertex to the first vertex. In this problem, we will try to determine whether a graph contains a Hamiltonian cycle or not. And when a Hamiltonian cycle is present, also print the cycle. Input and Output Input: The adjacency matrix of a graph G(V, E). Output: The algorithm finds the Hamiltonian path of the given graph. For this case it is (0, 1, 2, 4, ... Read More

Advertisements