The Traveling Salesman Problem (TSP) and Hamiltonian Path/Cycle problems are closely related, but they are not the same thing.
Hamiltonian path: A path that visits every vertex exactly once.
Hamiltonian cycle: A Hamiltonian path that returns to the starting vertex.
The question is existence:
Does such a path/cycle exist?
Type of problem: This is a decision problem.
Goal: You must visit every vertex exactly once and return home.
Edge weights: Every edge has a weight (distance, time, cost).
The question is optimization:
What is the minimum‑weight Hamiltonian cycle?
Type of problem: This is an optimization problem.
NP Problem refers to problems where a proposed solution can be verified quickly — in polynomial time — even if finding that solution might be extremely hard.
Nondeterministic: A theoretical machine could “guess” a correct solution instantly. We don’t need such a machine to exist — it’s just a mathematical model.
Polynomial time: Verification can be done in time like:
n, n², n³, etc.
If someone hands you a path or cycle, you can quickly check:
All of this is polynomial-time verification, so Hamiltonian Path and Cycle are NP decision problems.
NP Problem refers to problems where a proposed solution can be
verified quickly — in polynomial time — even if
finding that solution might be extremely hard.
Example of this type of problem:
Finding the shortest route that starts at City A, visits every
other city exactly once, and then returns to City A.
Before modern computers, solving this was extremely difficult because the number of possible routes grows explosively as more cities are added.
Mathematicians imagined a theoretical machine that could instantly evaluate all possible routes and choose the shortest one.
Today, that “theoretical machine” effectively exists — in the form of data centers and computer algorithms capable of processing enormous numbers of possibilities far faster than any human could.
NP problems are challenges where a proposed solution can be verified quickly — in polynomial time — even if finding that solution is extremely hard.
Find the shortest route that starts at City A, visits every other city exactly once, and returns to City A.
As cities increase, the number of possible routes grows explosively.
Before modern computing, mathematicians imagined a theoretical machine that could instantly evaluate all possible solutions — a foundation introduced by Alan Turing and later formalized by Stephen Cook in NP theory.
That “theoretical machine” effectively exists now as data centers, parallel computing, and advanced algorithms capable of processing massive search spaces far faster than humans ever could.
In a travelling salesman problem with 6 cities, the goal is to find the shortest possible route that starts at City A, visits each of the remaining five cities exactly once, and returns to City A.
The number of possible directed tours is given by:
P(n) = (n − 1)!
For six cities:
P(6) = 5! = 120
This matches the 120 possible combinations shown in the calculator (each representing a distinct ordered route).
In an undirected TSP, a route and its reverse direction represent the same path. To remove these duplicates, the number of unique tours is:
U(n) = (n − 1)! / 2
For six cities:
U(6) = 5! / 2 = 60
This means there are 60 unique undirected tours when reverse paths are treated as identical.
Click any cell to edit its weight. Use 1e9 to mark a forbidden transition.