Skip to content

Travelling Salesman - DP Optimisation using BitManipulation #3273

@Rytnix

Description

@Rytnix

Is your feature request related to a problem? Please describe.
In this algo we are going to use Bitmasking technique to solve famous NP-hard Traveling Salesman Problem.
As we know working with bits decreases the time complexity little bit.

Describe the solution you'd like
For min. distance between two cells we are going to use BFS.
For the overall we are going to maintain a dp state to track the visited houses and the last visited house to uniquely identify a state in this problem.
Therefore, we will be taking dp[index][mask] as our DP state.

Describe alternatives you've considered.
I didn't find the implementation of naive approach too. I will implement that also.

Additional context
The Time complexity of naive approach is (n!)
where as the TC of bitmask dp approach will be (n^2 * 2^n) which is better than the naive approach.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions