Number of Hamiltonian cycle

Given an undirected complete graph of N vertices where N > 2. The task is to find the number of different Hamiltonian cycle of the graph.

Complete Graph: A graph is said to be complete if each possible vertices is connected through an Edge.

Hamiltonian Cycle: It is a closed walk such that each vertex is visited at most once except the initial vertex. and it is not necessary to visit all the edges.

Formula:

Examples:

Input : N = 6
Output : Hamiltonian cycles = 60

Input : N = 4
Output : Hamiltonian cycles = 3

Explaination:
Let us take the example of N = 4 complete undirected graph, The 3 different hamiltonian cycle is as shown below:

Below is the implementation of the above approach:

filter_none

edit
close

play_arrow

link
brightness_4
code

chevron_right


Output:

Hamiltonian cycles = 12


My Personal Notes arrow_drop_up