0% found this document useful (2 votes)
598 views12 pages

Combinatorial Algorithms - Edward M Reingold

Algoritmos combinatorios de Edward m Rei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (2 votes)
598 views12 pages

Combinatorial Algorithms - Edward M Reingold

Algoritmos combinatorios de Edward m Rei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 12
Soke Ma tcyiare/es(°] Jurg Nievergelt Narsingh Deo | | Combinatorial PN efelaitairs Theory and Practice 7 Sec. 1.8 Analysis of Algorithms and verify that 1. Eachrow has exactly r ones, and hence the total number of ones in the matrixis sr. 2. Ineach column there are at most r ones (the verification of this point isthe subject of Exercise 12), and hence the total number of ones in the matrix is at most nr. Combining these, we obtain sr = nr, or s = n. (The simple trick of counting the elements of a matrix by rows and by columns and equating the result of the two counts goes amazingly far, as Section 3.4.2 will show). Having now established that W,(V) =n, observe the following facts about the weight-distribution in the n cube: 1, The total weight in the cube is N(7), since each of the N codewords contributes @ weight of one to each of the (°) vertices at distance r from it. 2. The total weight of all codewords D, is 2(N ~ r) (Exercise 13), and hence the total weight of all vertices outside ® is NC) — 2(N ~ 7), 3. Since there are 2" ~N vertices V outside @ and each of them has weight W,(V) 5 n, the total weight of all vertices outside @ is at most (2" — N)n. Combining (2) and (3), we obtain the inequality mo") - 20-9 SQ" Nn For fixed r and increasing n, (2) grows approximately as bn’, where b depends on r but not on n. With this information, we can show that which is inequality (1.4). ‘The reader who has worked through this chapter diligently, starting with the trivial bit sum algorithm that scans each bit in turn and ending with the demanding exercise of filling in the details of the derivation of the upper bound (1.4), has had a bird’s-eye view of the entire field of combinatorial algorithms. In particular, every topic encountered in this book will be a reminder of the principles of algorithm design illustrated in Sections 1.3 and 1.4, the consideration of details of implementation as discussed in Sections 1.1 and 1.2, and the mathematical techniques of algorithm analysis used in Sections 1.5 and 1.6. 64 Chap. 2. Representation of Combinatorial Objects element in G,. Thus for each of the |G,| elements in G,, there can be at most b(k + 1) ~ b(k) links in E,, Now notice that by Lemma 2.3 there are at most n/2" elements of rank 7 since each element of rank ris the root of asubtree containingat least 2" elements. Therefore sagt n wee an 2h lols Ee oe. fa) and that the asymptotic series on the right converges for no value of x. Investigate the error that is incurred when using the truncated series D7. (k—D!/x* to approximate f(x) as afunction of x and n. What value of n (asa function of x) gives the best approximation? Show tn [Uxmeae = aioe s [xine and then, using asymptotic expansion of the integrals, prove that Zkink = Finn —" + Otnlogm) Push the asymptotic expansion of equation (3.8) further to obtain Bint=(0+)ian—n+0den +0, Use the result of Exercise 6 to obtain Stirling's formula fot some constant g. It can be shown that o = V2. Find a closed-form expression for the sequence of numbers defined by X= x1 = 05, 25%, —%1 form B 1. In order to see the problems that can occur when recurrence relations are used for ‘numerical calculation, compute the first 10 to 15 terms f the sequence x, according to the recurrence relation. Use 2- and 3-digit decimal arithmetic; that is, round every x, to 2, respectively 3, significant decimal digits before calculating the next termin the sequence. Compare the computed values to the exactsolution. How do you explain the difference? Find the most general solution to the recurrence relation, = ip ~ Bigs 138 Chap. 4 Exhaustive Search 4.2.2 Recursive Sieves There are many sieves in which the moduli m,, m,... are not predeter- mined; the value of m, will depend on the numbers not eliminated after sifting with m,_. Many sieves are constructed in this recursive manner; in fact, the sieve of Eratosthenes is usually so constructed: after writing down the integers ,N, we cancel all multiples of 2 except 2. Then since the smallest ing number whose multiples have not been removedis 3, all multiples of 3, except 3, are removed, and so on. Notice that at each stage the first number removed is the square of the sifting number, and thus the first number eliminated by 2is 4, by 3, 9, and soon. When the sifting number becomes larger than VN, no other numbers can be removed and the process ends. Typically, we double the range of the sieve of Eratosthenes by presifting with 2;in other words, we begin with only the odd integers, sifting out multiples of 3, 5, 7, 11,and soforth. Letting X be the bit string, the recursive version of the sieve of Eratosthenes, with presifting by 2, for odd primes up to 2N + 1 is shown in Algorithm 4.5. Xe (11 2D fork = 3t0V2N* Iby2do [X42 represents the odd integer k] if Xq-y2 = 1 then fori = k?to2N + 1 by 2k do Xy-/ for k = 1 tN doit X, 1 then output 2k + 1 Algorithm 4.5 Sieve of Eratosthenes for odd primes. Another well-known recursive sieve produces the lucky numbers. From the list of numbers 1, 2, 3, 4, 5, . . . remove every second number, leaving the list 1, 3, 5,7, 9,.... Since 3 is the first number (excepting 1) that has not been used as a sifting number, we remove every third number from those remaining numbers, yielding 1, 3, 7, 9, 13, 15, 19, 21,... Now every seventh number is removed, leaving 1, 3,7, 9, 13, 15, 21,.... Numbers that are never removed from the list are considered to be “lucky.” In spite of the great similarity between the sieve of Eratosthenes and the lucky number sieve, the latter is harder to implement. The difficulty occurs because the numbers sifted out at the kth stage depend positionally on the elements not yet eliminated, not on the elements of the initial set. Assuming that abit representation is used, the lucky number sieve will have to count, say, every seventh 1-bit instead of every seventh bit. ‘This task is expedited considerably by the use of tags. Instead of using an entire computer word to represent the potential solutions through which we must sift, we use a portion of the word to store a count of the number of I-bits in the remainder of the word. For example, ona computer 175 Sec. 6.2 Subsets of Sets ‘The same transition sequences are obtained by a different recursive definition—namely, Tal Rat hht bhatt bot bl, (5) where T, = 1, f2,---, 42-1. This yields another recursive definition for the same codes. If /Go\ Gln) = is the n-bit code, then the (n + 1)-bit code can alternatively be defined by | Go0 \ Gol Gil Gin +1) =| GO G0 Gal This recursive definition is very close to a recursive definition of the binary representation of integers. If we have 212 63. Chap. 6 Fast Search Ina sequentially allocated table, consecutive names are stored in consecutive locations (see Figure 2.1). So deletion of a name creates a gap that must be filled, and insertion of a name demands that a gap be created. In either case, many names in the table must be moved or copied, and as Algorithm 6.4 shows, these operations require time O(n). insert z ati: nent forj = n ~ ltoiby ~ 1dox,., x, do j x, doj x,"in Algorithm 7.3, notice that at the end of the loop “while i < j” all the names 3y+1s- «5% have been compared once with x, except names x, and x, 1 (where the scans cross), which have been compared twice with x,. Let C, be the average number of name comparisons to sort a table of n distinct names, assuming that each of the n! permutations of the table is equally likely. Obviously C, = C, = 0 and in general we have G=Eamtit+GitG), 22 323 Sec. 8.2 Connectivity and Distance there exists at least one directed path from v; to v, and at least one from v; tov. A. graph consisting of a single isolated vertex is (trivially) connected. A maximal’ connected subgraph of a graph G is called a connected component or simply a component of G. A disconnected graph consists of two or more components. A maximal strongly connected subgraph is called a strongly connected component. ‘The most basic questions about a graph concern connectivity, paths, and distances. We may want to find out whether a graph is connected; if it is connected, we may want to find the shortest distance between a specified pair of vertices or to identify a shortest path between them. Ifthe graph is disconnected, ‘we may want to identify all its components. Algorithms for answering these and other related questions are developed in this section. 821 Spanning Trees A connected, undirected acyclic graph is called a tree, and a set of trees is called a forest. We have already seen rooted trees and forests of rooted trees in the preceding chapters, but the (unrooted) trees and forests discussed in this chapter are graphs of a very special kind that play an important role in many applications. In a connected undirected graph G there is at least one path between every pair of vertices in G; the absence of a cycle in G implies that there is at most one such path between any pair of vertices in G. Thus if G is a tree, there is exactly one path between every pair of vertices in G. The argument is easily reversed, and so an undirected graph G is a tree if and only if there is exactly one path between every pair of vertices in G. Since n — 1 edges are the fewest possible to connect vertices (why?) and a tree with n vertices contains exactly n ~ 1 edges (Exercise 4), trees can be thought of as graphs that are minimally connected. Removing any edge from a tree renders it disconnected by destroying the only path between at least one pair of vertices. Of particular interest are spanning trees of a graph G, trees that are subgraphs of G and contain every vertex of G. If G is not connected, a set consisting of a spanning tree for each component is called a spanning forest of G. To construct a spanning tree (forest) of a given undirected graph G, we examine edges of G one ata time and retain those that do not form acycle with the edges already selected Inaweighted graph G = (V, E)itisoften of interest to determine aspanning tree (forest) of minimum total edge weight—that is, such that the sum of the weights of all edges isminimum. Such tree is called a minimum spanning tree. A minimum spanning tree can be found by applying the process described above with edges examined in increasing order of their weights. In other words, at each stage we choose the smallest unused edge that does not form a cycle with the edges ‘We make a distinction between the two adjectives “maximal” and “maximum.” A set $ is a ‘maximal set satisfying a certain property P if there is no set properly containing S that satisfies property P. Set 5 is maximum if there exists no set of greater cost, according to some cost function (such as cardinality), that satisfies property P. The corresponding distinction is also made between, ‘minimal and minimum. Chap. 8 Graph Algorithms Isomorphic graphs differ only in the labeling of the vertices, and thus the problem of determining isomorphism occurs in a number of practical situations, such as information retrieval and identification of chemical compounds. Notice that, as in the case of generating all cycles of a graph (Section 8.3.2), we can restrict our attention to digraphs. Any undirected graph can be trans- formed to a directed graph by replacing each edge with two oppositely directed edges. Two digraphs thus obtained are obviously isomorphic if and only if the original graphs are isomorphic. ‘The most straightforward method of checking for isomorphism of graphsis to use backtrack to examine all the n ! possible correspondences between the vertices of two n-vertex digraphs. When n is larger than about 13, this unconstrained backtrack is unsatisfactory because of the size of n!. However, with suitable pruning of the search tree, this method forms the basis of a reasonable digraph isomorphism algorithm Define the indegree (outdegree) of a vertex in a digraph as the number of edges entering (leaving) the vertex. Obviously, a vertex v, in G, cannot be mapped by an isomorphism to the vertex v in G, unless both indegree (v,) = indegree (v2) and outdegree (v,) = outdegree (v2). So in Figure 8.20 an isomorphism is limited to correspondences between the following subsets of vertices: {3} © fb} {2} > {a} {1,4, 5} © {d,e, f} {6} > {ce} Thus only 3! = 6 correspondences instead of 6! = 720 need be checked, a considerable savings. It is this approach that we use in developing a digraph isomorphism algorithm, ‘Suppose that we are given two digraphs, Gx = (Vx, Ex) and Gy = (Vy, Ey), to be tested to determine if Gx = Gy. We assume that Vx = Vy = {1, 2,...4m}forif|Vx| # [Vvl the digraphs cannot possibly be isomorphic, Let one of the digraphs, say Gx, be selected as the reference digraph. Let Gx) denote the subgraph of Gy induced by the vertices {1,2,...,k} 02k = Cleatly, Gix(0) 5 the empty subgraph and Gy (1) isthe subgraph consisting of @ single vertex 1 and no edges. In determining whether Gx = Gy, we use a backtrack technique. Obviously, G(0) is isomorphic to the empty subgraph of Gy. Suppose that at some point we have found a subgraph of Gy consisting of vertices Sc Vy that is isomorphic to Gx(k). We try to extend the isomorphism to Gx(k + 1) by choosing a vertex » € Vy ~ $ to correspond to k +1 Vy. If we find such a v, we record the correspondence by setting f,,., « v and try to extend the isomorphism to Gx(k + 2). If there is no such v, we back up to Gx(k ~ 1) and try to choose a different vertex to correspond to k € Vx. This, 397 Sec. 88 Exercises 34, #35, 36. 37. 38. 39. 40. ai. Use the dynamic programming approach of section 4.1.7 to obtain an algorithm for finding the shortest path between two vertices of a weighted digraph. How does ‘your algorithm compare to Algorithm 8.8 in the number of operations required? Design, analyze, and prove correct an efficient algorithm to generate all the cycles of an undirected graph, given a fundamental set of cycles. In Algorithm 8.11(0), prove that during the execution of CYCLE (s,f), for any vertex x # 5, there isa call to UNMARK (0) that causes avail (x) « true if and only if (2) there is a path containing v from x to s on which only » and s are on the path stack, (©) there is no path from x to s on which only s is on the path stack. Use this result to prove that Algorithm 8.11 generates every cycle exactly once. Prove that in Algorithm 8.11 the number of operations performed between acallto CYCLE and either the return or the generation of a cycle is O(|V| + |E)). (Hint: Use the result of Exercise 36.) Use this result to prove that the total number of operations required by Algorithm 8.11 to generate all the eycles is O(|V| + [ED (1 + 2), where ¢ is the number of cycles, Give an example of a graph in which applying Theorem 8.2 iteratively causes a clique to be missed. (Hint: One such example has five vertices and seven edges.) Prove that the modified Algorithm 8.12 generates each of the cliques of a graph exactly once. [Hint: Using Theorems 8.2 and 8.3, prove by induction on |N| that the call CLIQUE (N, D) generates each clique of G in the subgraph induced by NUS exactly once.] Let G = (V, £) be an undirected graph with V = {1,2,...,m}, and let 1 n, be the “subgraph of G induced by the subset of vertices {1,2,...,}. Consider the following inductive method for finding the cliques of G: ‘Assume that the set, of all cliques of G,_, has been found. For each clique Ce €,., we have ( IEC c Adj@ then CU fib € & (i) CZ Adj( then Ce &, Gi) If CZ Adj (@ then[C N Adj () U {i}isa complete subgraph of G, and may or may not be a clique. Thus each clique C € ,-. generates a distinct clique in by either () or i). A second clique in 6, may be generated by (ii). . (a) Prove that if C e then C can be generated from some € € %,_, by either (i), Gi), oF Gi (b) Use this technique to obtain an algorithm to determine all the cliques of graph. A clique C of a graph G is called a maximum clique if no clique in G contains more vertices than C. Devise a branch-and-bound algorithm to find a maximum clique of a graph,

You might also like