Input: graph[][] = [[0, 1, 0, 1, 0], [1, 0, 1, 1, 1], [0, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 1, 1, 1, 0]]
Input graph[][]Output: 0 1 2 4 3 0
Input: graph[][] = [[0, 1, 0, 1, 0], [1, 0, 1, 1, 1], [0, 1, 0, 0, 1], [1, 1, 0, 0, 0], [0, 1, 1, 0, 0]]
Input graph[][]
Output: Solution Does Not Exists
The idea is to use backtracking to determine whether the given graph contains a Hamiltonian Cycle. Initialize an empty path array and place the starting vertex (e.g., vertex 0) at the first position. Recursively try to add the remaining vertices one by one. Before placing a vertex, ensure it is adjacent to the previously added vertex and has not already been used in the path. If a valid vertex is found, proceed forward; otherwise, backtrack and try another option.