Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
In this chapter we introduce the theory of ``intractability'', that is techniques for showing problems not to be solvable in polynomial time.
and
NP
1. Maintain for each node the connected component in which the node appears, using whatever edges of the tree have been selected so far. Initially, no edges are selected, so every node is then in a connected component by itself. 2. Consider the lowest-weight edge that has not yet been considered; break ties anyway you like. If this edge connects two nodes that are currently in different connected components then: - Select that edge for the spanning tree, and - Merge the two connected components involved, by changing the component number of all nodes in one of the two components to be the same as the component number of the other. If, on the other hand, the selected edge connects two nodes of the same component, then this edge does not belong in the spanning tree; it would create a cycle. 3. Continue considering edges until either all edges have been considered, or the number of edges selected for the spanning tree is one less than the number of nodes. Note that in the latter case, all nodes must be in one connected component, and we can stop considering edges.
Example 1.1 In the graph of fig 55, we first consider the edge (1,3), because it has the lowest weight, 10. since 1 and 3 are initially in different components, we accept this edge, and make 1 and 3 have the same component number, say ``component 1''. The next edge in order of weights is (2,3), with weight 12. Since 2 and 3 are in different components, we accept this edge and merge node 2 into ``component 1''. The third edge is (1,2), with weight 15. However, 1 and 2 are now in the same component, so we reject this edge and proceed to the fourth edge, (3,4). Since 4 is not in ``component 1'', we accept this edge. Now, we have three edges for the spanning tree of a 4-node graph, and so may stop. It is possible to implement this algorithm(using a computer not a TM) on a graph with m nodes and e edges in time O (m + e log e) . A simpler implementation proceeds in e rounds. A table gives the current component of each node. We pick the lowest-weight remaining edge in O (e) time, and find the components of the two nodes connected by the edge in m time. If they are in different components, merge all nodes wth those numbers in O (m) time, by scanning the table of nodes. The total time taken by this algorithm is O (e(e + m)) . This running time is polynomial in the ``size'' of the input, which we might informally take to be the sum of e and m . When we translate the above ideas to Turing Machines, we face several issues: When we study algorithms we encounter problems that ask for outputs in a variety of forms, such as a list of edges in a MWST. When we deal with Turing machines, we
may ony think of problems as languages, and th only output is yes or no, i.e. accept or reject. For instance, the MWST tree problem could be couched as: ``Given this graph G and limit W , does G have a spanning tree of weight W or less?'' That problem may seem easier to answer han the MWST problem with which we are familiar, since we don't even learn what the spanning tree is. However, in the theory of intractability. we generally want to argue that a problem is hard, not easy, and the fact that a yes-no version of a problem is hard implies that a more standard version, where a full answer must be computed, is also hard. While we might think informally of the size of a graph as the number of nodes or edges, the inout to a TM is a string over a finite alphabet. Thus, problem elements such as nodes and edges must be encoded suitably. The effect of this requirement is that inputs to Turing Machines are generaly slightly longer than the intuitive size of the input. However there are two reasons why the difference is not significant: (a) The difference between the size as a TM input string and as an informal problem inout is never more than a small factor, usually the logarithm of the input size. Thus, what can be done in polynomial time using one measure can be done in polynomial time using the other measure. (b) The length of a string representing the input is actually a more accurate measure of the number of bytes a real computer has to read to get its input. For instance, if a node is represented by an integer, then the number of bytes needed to represent that integer is proportional to the logarithm of the integer's size, and it is not ``1 byte for any node'' as we might imagine in an informal accounting for input size. Example 1.2 Let us consider a possible code for the graphs and weight limits that could be input to the MWST problem. The code has five symbols, 0,1, the left and right parentheses, and the comma. 1. Assign integers 1 through m to the nodes. 2. Begin the code with the value of m in binary and the weight limit W in binary, separated by a comma. 3. If there is an edge between nodes i and j with weight w , place (i, j , w) in the code. The integers i, j , and w are coded in binary. The order of i and j within an edge, and the order of edges within the code are immaterial. Thus, one of the possible codes for graph of Fig 55 with limit W = 40 is 100,101000(1,10,1111)(1,11,1010)(10,11,1100)(10,100,10100)(11,100,10010) If we represent inouts to the MWST problem as in Example 1.2, then an inout of length n can represent at most O ( n/logn) edges. It is possible that m , the number of nodes, could be exponential in n , if there are very few edges. However, unless the number if
edges, e , is atleast m -1, the graph cannot be connected and therefore will have no MWST, regardless of it's edges. Consequently, if the number of nodes is not atleast some fraction of n/log n , there is no need to run Kruskal's algorithm at all; we simply say ``no; there is no spanning tree of that weight.'' Thus, if we have an upper bound on the running time of Kruskal's algorithm as a function of m and e , such as the upper bound O (e(m + e)) developed above, we can conservatively replace both m and e by n and say that the running time, as a function of the input length n is O (n(n + n)) , or O(n 2 ) . We claim that in O( n 2 ) steps we can implement the version of Kruskal's algorithm described above on a multitape TM. The extra tapes are used for several jobs: 1. The input tape can hold the code for graph beginning with the number of nodes, the limit W and the edges as described in Example 1.2. 2. The second tape stores the list of nodes and their current components. This tape is O(n) in length. 3. A third tape is used to store the current least weight edge. Scanning for the lowestweight unmarked edge takes O(n) time. 4. When an edge is selected in a round, place it's two nodes on a fourth tape. Search the table of nodes and components to find the components of these two nodes. This requires O(n) time. 5. A tape can be used to hold the two components i and j , being merged. We scan the table of nodes and components and each node found to be in component i has its component number changed to j . This scan takes O(n) time.
We should thus be able to say that one round can be executed in O(n) time on a multi-tape TM. Since the number of rounds, e , is at most n , we conclude that O(n 2 ) time suffices on a multi-tape TM. Theorem 6.1 says that whatever a multitape TM can do in s steps, a single-tape TM can d in O ( s 2 ) steps. Thus, if the multitape TM takes O(n 2 ) steps, then we can construct a single-tape TM to do the same thing in 0( n 4 ) steps. Our conclusion is that the yes-no version of the MWST problem, ``does graph G have a MWST of total weight W or less,'' is in P .
References
[1] Sudkamp A. Thomas, Languages and Machines, An Introduction to the Theory of Compute Science, Addison Wesley Publishing Company, Inc.,United States of America, 1997.