Você está na página 1de 8

Soluciones Ejercicios 8.

3
Problema 2
a) a. For a graph with n vertices, the algorithm computes n matrices R(k) (k = 1, 2, ..., n),
each of which has n2 elements. Hence, the total number of elements to be computed
is n3. Since computing each element takes constant time, the time efficiency of the
algorithm is in (n3).
b) Since one DFS or BFS traversal of a graph with n vertices and m edges, which is
represented by its adjacency lists, takes (n + m) time, doing this n times takes
n(n+m) = (n2+nm) time. For sparse graphs (i.e., if m O(n)), (n2 + nm) = (n2),
which is more efficient than the (n3) time efficiency of Warshalls algorithm.
Adems, se trabaja una estructura de matriz, por lo que complejidad en tiempo es n2.

Problema 5
False. Here is a simple counterexample: A(0.3), B(0.3), C(0.4). (The numbers in the parentheses
indicate the search probabilities.) The average number of comparisons in a binary
search tree with C in its root is 0.32 + 0.33 + 0.41 = 1.9, while the average number of
comparisons in the binary search tree with B in its root is 0.31 + 0.32 + 0.42 = 1.7.

Ejercicios 8.4
Problema 1

Problema 6
a. Explain how Warshalls algorithm can be used to determine whether a given digraph is a dag
(directed acyclic graph). Is it a good algorithm for this problem?
With the books definition of the transitive closure (which considers only nontrivial paths of a
digraph), a digraph has a directed cycle if and only if its transitive closure has a 1 on its
main diagonal. The algorithm that finds the transitive closure by applying Warshalls
algorithm and then checks the elements of its main diagonal is cubic. This is inferior to
the quadratic algorithms for checking whether a digraph represented by its adjacency
matrix is a dag, which were discussed in Section 5.3.

b. Is it a good idea to apply Warshalls algorithm to find the transitive closure of an undirected
graph?
No. If T is the transitive closure of an undirected graph, T[i, j]=1 if and only if there is a
nontrivial path from the ith vertex to the jth vertex. If i = j, this is the case if and only if
the ith vertex and the jth vertex belong to the same connected component of the
graph. Thus, one can find the elements outside the main diagonal of the transitive
closure that are equal to 1 by a depth-first search or a breadth-first search traversal,
which is faster than applying Warshalls algorithm. If i = j, T[i, i]=1 if and only if the ith
vertex is not isolated, i.e., if it has an edge to at least one other vertex of the graph.
Isolated vertices, if any, can be easily identified by the graphs traversal as one-node
connected components of the graph.

Problema 7

Problema 9
Give an example of a graph or a digraph with negative weights for which Floyds algorithm
does not yield the correct result.

Ejercicios 9.2
Problema 1
Apply Kruskals algorithm to find a minimum spanning tree of the following graphs

2. Indicate whether the following statements are true or false:


a. If e is a minimum-weight edge in a connected weighted graph, it must be among edges of
at least one minimum spanning tree of the graph.
True. (Otherwise, Kruskals algorithm would be invalid.)
b. If e is a minimum-weight edge in a connected weighted graph, it must be among edges of
each minimum spanning tree of the graph.
False. As a simple counterexample, consider a complete graph with three vertices and the
same weight on its three edges
c. If edge weights of a connected weighted graph are all distinct, the graph must have exactly
one minimum spanning tree.
True (Problem 10 in Exercises 9.1).
d. If edge weights of a connected weighted graph are not all distinct, the graph must have
more than one minimum spanning tree.
False (see, for example, the graph of Problem 1a).

Problema 4
Does Kruskals algorithm work correctly on graphs that have negative edge weights?
Si, por el ordenamiento de las aristas ascendentemente y pasa por aquellas que se sabe son de
menor peso.

Ejercicios 9.3
Problema 2: Solve the following instances of the single-source shortest-paths problem with
vertex a as the source:

Problema 3: Give a counterexample that shows that Dijkstras algorithm may not work for a
weighted connected graph with negative weights.

Problema 4: Let T be a tree constructed by Dijkstras algorithm in the process of solving the
single-source shortest-path problem for a weighted connected graph G.
a. True or false: T is a spanning tree of G?
TRUE. On each iteration, we add to a previously constructed tree an edge connecting a vertex
in the tree to a vertex that is not in the tree. So, the resulting structure must be a tree. And,
after the last operation, it includes all the vertices of the graph. Hence, its a spanning tree.

b. True or false: T is a minimum spanning tree of G?


FALSE.
Here is a simple counterexample:

Você também pode gostar