Toc Unit5
Toc Unit5
Tractable Problems
Aspect Description
Problems that can be solved in polynomial time (i.e., their time complexity
Definition
can be expressed as a polynomial function of the size of the input).
Time
Polynomial time (e.g., O(n), O(n^2), O(n^3))
Complexity
Sorting algorithms (e.g., merge sort), finding the shortest path (e.g.,
Examples
Dijkstra's algorithm), searching (e.g., binary search)
Considered "feasible" or "efficiently solvable" because the computation time
Feasibility
grows at a manageable rate as the input size increases.
Class Includes problems in the class P (Polynomial Time).
Impact Solutions are practical for large inputs.
Intractable Problems
Aspect Description
Problems for which no polynomial-time algorithms are known, and are often
Definition
believed to require super-polynomial time to solve.
Time
Super-polynomial time (e.g., exponential time, factorial time)
Complexity
Examples Traveling Salesman Problem, 3-SAT, integer factorization
Considered "infeasible" or "impractical" for large inputs because the
Feasibility
computation time grows very quickly as the input size increases.
Includes problems in NP (Nondeterministic Polynomial time) and
Class
specifically NP-Hard and NP-Complete problems.
Aspect Description
Solutions are impractical for large inputs; approximate or heuristic solutions
Impact
may be used instead.
Summary
Tractable Problems: These are problems that can be solved efficiently (in
polynomial time), making them practical for use even with large inputs.
Intractable Problems: These problems cannot be solved efficiently (they require
super-polynomial time), making them impractical for use with large inputs.
In practice, for intractable problems, researchers often look for approximate or heuristic
solutions that provide good-enough answers within a reasonable time frame.
Problem Definition: Given a set of cities represented as vertices in a graph, and distances
between each pair of cities as edge weights, find the Hamiltonian cycle with the minimum
total weight. A Hamiltonian cycle is a path in the graph that visits each vertex exactly once
and returns to the starting vertex.
NP: We can efficiently verify if a given solution (a route visiting all cities) is indeed a
minimum distance route.
NP-hard: Finding the optimal solution itself is computationally difficult. There's no
known efficient algorithm (polynomial time) that can solve TSP for all problem sizes.
As the number of cities increases, the number of possible routes grows exponentially,
making it intractable to check them all for optimality.
Imagine we have a salesperson visiting 4 cities: A, B, C, and D. The distances between them
are represented in a distance matrix:
City A B C D
A - 5 7 3
B 5 - 6 4
C 7 6 - 2
D 3 4 2 -
Here, the distance matrix shows the cost (distance) of traveling between any two cities.
Graph Representation:
Edges connect every pair of cities, indicating a possible route between them.
The weight on each edge represents the distance between the connected cities.
In theory, to find the optimal route (shortest cycle), we would need to check every possible
Hamiltonian cycle and calculate its total weight. With 4 cities, there are 4! (4 factorial) = 24 possible
Hamiltonian cycles. We could calculate the total distance for each and pick the one with the
minimum weight.
However, as the number of cities increases, the number of possible Hamiltonian cycles grows
exponentially. For 10 cities, there are 10! = 3,628,800 possibilities, making it impractical to check
them all using a brute-force approach.
This is why TSP is classified as NP-hard. While we can verify if a given Hamiltonian cycle is optimal by
simply summing the edge weights (NP), finding the optimal cycle itself becomes computationally
expensive for larger problems (hard).
This example illustrates the concept of NP-hardness in TSP within the theory of computation. Even
for a small graph, finding the optimal solution requires significant effort. In practice, for bigger
problems, we often rely on approximation algorithms that provide good (but not guaranteed
optimal) solutions in a reasonable amount of time.
The partition problem asks whether a given set of positive integers can be divided into two
subsets where the sum of elements in each subset is equal. Here's a breakdown with an
example:
Problem Definition:
Imagine you have a bag of weights: {2, 3, 7, 1}. The partition problem asks if you can divide
these weights into two groups such that the total weight in each group is the same.
Why? Because each weight is a positive integer, and dividing an odd number into two
equal parts isn't possible.
Let's say we have a different bag of weights: {1, 5, 11, 2}. Here, the total weight is 1 + 5 + 11
+ 2 = 19. Since 19 is even (divisible by 2), it becomes a candidate for partitioning.
1. Check for even sum: The first step is always to check if the total sum of all weights
is even. If it's odd, as in our first example, partition is not possible.
2. Target sum: Since the total weight is 19 (even), we can aim to partition the weights
into two subsets where each subset has a sum of 19 / 2 = 9.5. However, since we're
dealing with whole weights, we can rephrase this as checking if a subset exists where
the sum of its elements is exactly 9 (half of the total weight, rounded down).
3. Solution Approach: There are different ways to solve the partition problem. One
approach is dynamic programming, which builds a table to efficiently track if a subset
with a specific sum exists for a given weight set.
In simpler terms, for each weight in the set, we can iteratively check if including that weight
in a subset helps us reach the target sum (9 in our example). This might involve checking if
there's already a valid subset formed by previous weights that, when combined with the
current weight, reaches the target sum.
The partition problem is interesting because it's known to be NP-complete. This means:
NP: Given a specific partition (two subsets with equal sum), we can efficiently verify
if it's a valid partition for the original weight set (by simply adding the elements in
each subset).
NP-hard: Finding the partition itself is computationally difficult. There's no known
efficient algorithm (polynomial time) to solve the partition problem for all problem
sizes. As the number of weights increases, the number of possible combinations to
explore grows exponentially.
Real-world applications:
While the partition problem might seem abstract, it has applications in various scenarios
where we need to divide resources or tasks into equal groups. For example: