Page Content

Tutorials

What are the Types of Intractable Problems With Example

Types of Intractable Problems

Types of Intractable Problems
Types of Intractable Problems

Classic mathematical and computer science issues like Hamiltonian Paths and Cycles, the Knight’s Tour, and the Travelling Salesperson Problem are frequently studied in relation to graph theory and computational complexity. Because these issues are classified as intractable, they are grouped together.

Intractable Problems

Intractable problems have no polynomial-time algorithm. This suggests that the most well-known strategies take increasingly longer to solve the problem with large inputs, making it nearly types of intractable problems to solve. A fundamental component of computer science that this book seeks to teach is how to recognise when an algorithm or data structure will fail in a particular use case.

The Knight’s Tour

Finding a knight’s move pattern on a chessboard that allows the knight to visit each square precisely once is the goal of the Knight’s Tour puzzle. This issue is included in the list of unsolvable issues. If a knight may move between two vertices, then there is an edge between them. In the context of graphs, a chessboard can be represented as a graph in which each square is a vertex. In this graph, a Knight’s Tour then turns into a certain kind of path. The accounts call the Knight’s Tour types of intractable Problems. Classify it under this subject but don’t explain The Knight’s Tour dilemma or how to overcome it.

The Traveling Salesperson Problem (TSP)

Another well-known instance of an unsolvable issue is the Travelling Salesperson Problem (TSP). In this issue, a salesperson must travel to a number of locations and then return to the starting city. The objective is to determine the quickest route that makes precisely one stop in each city.

Problem Formulation: TSP can be expressed in terms of graph theory as locating a minimum-weight Hamiltonian cycle in a weighted graph. If the graph is directed, movement is limited to the direction of the edge; if it is undirected, the path can be followed in either direction. The cost or distance between cities is usually represented by the “weight” of an edge.

Computational Difficulty: The Travelling Salesperson Problem is a well-known, unsolvable issue. This implies that determining the absolute shortest path for a large number of cities is computationally very costly and frequently calls for algorithms whose execution times increase dramatically (e.g., exponentially) with the number of cities.

Example:

from itertools import permutations
def calculate_distance(graph, path):
    return sum(graph[path[i]][path[i + 1]] for i in range(len(path) - 1)) + graph[path[-1]][path[0]]
def traveling_salesman(graph):
    n = len(graph)
    min_path = float('inf')
    best_path = []
    for perm in permutations(range(n)):
        current_distance = calculate_distance(graph, perm)
        if current_distance < min_path:
            min_path = current_distance
            best_path = per
   return min_path, best_path
graph = [
    [0, 10, 15, 20],
    [10, 0, 35, 25],
    [15, 35, 0, 30],
    [20, 25, 30, 0]
]
min_distance, path = traveling_salesman(graph)
print(f"Minimum Distance: {min_distance}")
print(f"Path: {path}")

Output:

Minimum Distance: 80
Path: (0, 1, 3, 2)

Hamiltonian Paths and Cycles

In graph theory, Hamiltonian pathways and cycles are basic ideas that have a direct bearing on issues such as the Travelling Salesperson Problem. Hamiltonian Paths and Cycles are mostly explored in graph structures. It call Hamiltonian Paths and Cycles intractable. Types of Intractable problems are computationally difficult to solve. In addition to Hamiltonian Paths and Cycles, the Knight’s Tour and Travelling Salesperson Problem are intractable. It classify them by difficulty but do not define Hamiltonian Paths or Cycles.

Definition:

  • Hamiltonian paths visit each vertex once in a graph.
  • Hamiltonian cycles start and end at the same vertex. This indicates that the cycle has exactly one instance of each vertex in the graph.

Intractability: Another example of an intractable problem is the difficulty of identifying whether a given graph contains a Hamiltonian path or cycle. This is a crucial component since, for big graphs, even identifying the presence of such a path or cycle might take an excessive amount of time. For example, graph traversal discussions address the problem of finding cycles in directed graphs.

Relationship to TSP: In essence, the Travelling Salesperson Problem looks for a Hamiltonian cycle in a weighted graph that has the lowest overall weight. Therefore, looking for or improving Hamiltonian cycles is frequently necessary to develop effective solutions for TSP.

Example:

def is_valid_vertex(v, pos, path, graph):
    if graph[path[pos - 1]][v] == 0:
        return False
    if v in path:
        return False
    return True
def hamiltonian_cycle_util(graph, path, pos):
    if pos == len(graph):
        return graph[path[pos - 1]][path[0]] == 1
    for v in range(1, len(graph)):
        if is_valid_vertex(v, pos, path, graph):
            path[pos] = v
            if hamiltonian_cycle_util(graph, path, pos + 1):
                return True
            path[pos] = -1 
    return False
def hamiltonian_cycle(graph):
    n = len(graph)
    path = [-1] * n
    path[0] = 0
    if not hamiltonian_cycle_util(graph, path, 1):
        print("No Hamiltonian Cycle exists")
    else:
        print("Hamiltonian Cycle:", path + [path[0]])
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]
]
hamiltonian_cycle(graph)

Output:

Hamiltonian Cycle: [0, 1, 2, 4, 3, 0]

Why are these problems intractable?

According to these issues are regarded as unsolvable since there isn’t a known algorithm that can resolve them in polynomial time. This suggests that the temporal complexity of solving a problem increases significantly quicker than any polynomial function (e.g., 2^n, n!), depending on the magnitude of the input (e.g., the number of vertices for Hamiltonian problems, the number of cities for TSP, or the number of squares on the chessboard for Knight’s Tour). Even with powerful computers, they are nearly impossible to solve for big instances in realistic timescales due to their exponential growth. Knowing “when an algorithm and/or data structure in Python will fail in a given use case” is one of the fundamental concepts of computer science.

Kowsalya
Kowsalya
Hi, I'm Kowsalya a B.Com graduate and currently working as an Author at Govindhtech Solutions. I'm deeply passionate about publishing the latest tech news and tutorials that bringing insightful updates to readers. I enjoy creating step-by-step guides and making complex topics easier to understand for everyone.
Index