Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Data Structures and Algorithms: Key to Homework Assignment 9 - Graph Theory, Assignments of Data Structures and Algorithms

Solutions and explanations for various graph theory problems from a data structures and algorithms course. It covers topics such as connected graphs, free trees, simple cycles, dijkstra's algorithm, prim's mst algorithm, and spanning trees. Students can use this document as a study resource for understanding these concepts and solving related problems.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-4qb-1
koofers-user-4qb-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Structures and Algorithms
Key to Homework Assignment 9
1. In class we stated the following result: Suppose Gis a connected, undirected graph with n
vertices. If the number of edges in Gis n1,then Gis a free tree.
First note that the result can be proved by drawing the different cases if Ghas 1 or 2 vertices.
So we may as well assume that n3.
Since a free tree is a connected graph with no simple cycles, one way to prove this is to look
at the contrapositive: Suppose Gis a connected, undirected graph with n3 vertices. If G
contains a simple cycle, then the number of edges in Gis at least n.
In order to prove this, we take a connected graph Gcontaining a simple cycle Con kvertices.
As noted in the text, the smallest simple cycle has 3 vertices. So k3.Now we can use
induction on the number mof vertices in the complement of C, and k, the number of vertices
in C, is fixed.
(a) Prove the base case. That is, show that if Gis a connected graph with k3 vertices
and Gcontains a simple cycle on all kvertices, then Gcontains at least kedges. Hint:
Count the edges in a simple cycle.
Suppose the simple cycle is (v0, v1,...,vk1, v0).Then the edges in the cycle are e1=
{v0, v1}, e2={v1, v2},...,ek1={vk2, vk1}, ek={vk1, v0}.Since the cycle is simple,
ei6=ejwhenever i6=j. Thus, There are at least n=kdistinct edges in G.
(b) State the induction hypothesis.
Let Gbe a connected, undirected graph subject to the following hypotheses.
i. Gcontains n=m+kvertices, where m=m00 and k3.
ii. Gcontains a simple cycle Con kvertices.
Then Ghas at least n=m+kedges.
(c) What do you need to show in the induction step? What are you assuming? What do
you need to prove?
Suppose Gis a connected, undirected graph subject to the following hypotheses.
i. Gcontains n=m0+1+kvertices, where m00 and k3.
ii. Gcontains a simple cycle Con kvertices.
Then we want to show that Gcontains at least n=m0+1+kedges.
(d) Extra Credit. Complete the induction step. Hint: in going from the case m=m0+ 1
vertices in the complement of Cto the case m=m0vertices in the complement of C,
use a DFS of G. The DFS should visit the vertices in Cfirst. Then the vertex that needs
to be deleted can be chosen to be a leaf in the depth-first spanning tree.
1
pf3

Partial preview of the text

Download Data Structures and Algorithms: Key to Homework Assignment 9 - Graph Theory and more Assignments Data Structures and Algorithms in PDF only on Docsity!

Data Structures and Algorithms

Key to Homework Assignment 9

  1. In class we stated the following result: Suppose G is a connected, undirected graph with n vertices. If the number of edges in G is n − 1 , then G is a free tree. First note that the result can be proved by drawing the different cases if G has 1 or 2 vertices. So we may as well assume that n ≥ 3. Since a free tree is a connected graph with no simple cycles, one way to prove this is to look at the contrapositive: Suppose G is a connected, undirected graph with n ≥ 3 vertices. If G contains a simple cycle, then the number of edges in G is at least n. In order to prove this, we take a connected graph G containing a simple cycle C on k vertices. As noted in the text, the smallest simple cycle has 3 vertices. So k ≥ 3. Now we can use induction on the number m of vertices in the complement of C, and k, the number of vertices in C, is fixed.

(a) Prove the base case. That is, show that if G is a connected graph with k ≥ 3 vertices and G contains a simple cycle on all k vertices, then G contains at least k edges. Hint: Count the edges in a simple cycle. Suppose the simple cycle is (v 0 , v 1 ,... , vk− 1 , v 0 ). Then the edges in the cycle are e 1 = {v 0 , v 1 }, e 2 = {v 1 , v 2 },... , ek− 1 = {vk− 2 , vk− 1 }, ek = {vk− 1 , v 0 }. Since the cycle is simple, ei 6 = ej whenever i 6 = j. Thus, There are at least n = k distinct edges in G. (b) State the induction hypothesis. Let G be a connected, undirected graph subject to the following hypotheses. i. G contains n = m + k vertices, where m = m 0 ≥ 0 and k ≥ 3. ii. G contains a simple cycle C on k vertices. Then G has at least n = m + k edges. (c) What do you need to show in the induction step? What are you assuming? What do you need to prove? Suppose G is a connected, undirected graph subject to the following hypotheses. i. G contains n = m 0 + 1 + k vertices, where m 0 ≥ 0 and k ≥ 3. ii. G contains a simple cycle C on k vertices. Then we want to show that G contains at least n = m 0 + 1 + k edges. (d) Extra Credit. Complete the induction step. Hint: in going from the case m = m 0 + 1 vertices in the complement of C to the case m = m 0 vertices in the complement of C, use a DFS of G. The DFS should visit the vertices in C first. Then the vertex that needs to be deleted can be chosen to be a leaf in the depth-first spanning tree.

Data Structures and Algorithms, Key to Homework 9 2

The idea is similar to one we’ve used many times before: delete a vertex and its incident edges; use the IH to conclude that the result holds for the new, smaller graph; add back the vertex and the incident edges to get the result for the original graph. The tricky part is that we might disconnect the graph if we delete just any vertex in the complement of C. So we use DFS to make sure that we delete a vertex that won’t disconnect. Carry out a DFS of G, starting at a vertex of C, and always visiting vertices of C before other vertices, and visiting the vertices of C in order: first v 0 , then v 1 , etc. Since G is connected, this will create a spanning tree (as opposed to a forest). The vertices of C will lie on the path consisting of the first k left branches of the tree. Since there is a vertex not in C, there must be a vertex in the spanning tree that’s not in C. Since G is connected, there’s a tree edge in the spanning tree joining a vertex w not in C to a vertex of C. Consider the subtree rooted at w. By the usual argument this subtree has a leaf u. Now consider the graph G′^ obtained from G by removing u and all its incident edges. Then C is a subgraph of G′^ and G′^ is connected: the depth-first spanning forest for G′ is simply the spanning tree of G with u and its incident edge deleted. So by the IH, G′^ contains at least m 0 +k edges. When we return u and its incident edges to G′, recovering G, we add at least one edge, the tree edge joining u to the spanning tree. Thus, G contains at least n = m 0 + 1 + k edges.

  1. Problem 7.13, page 221. The single-destination shortest paths problem for a directed graph is to find the shortest path from every vertex to a given vertex v 0. Write an algorithm to solove the single-destination shortest paths problems. Basically Dijkstra’s algorithm will do the job, with the caveat that in loops having the form

for each vertex w adjacent to v do

...

we’re now looking for edges from w to v. So the algorithm should either traverse the column of the adjacency matrix headed by v, or it should use an adjacency list which shows edges into the vertex at the head of the list.

  1. Problem 7.17, page 222. List the order in which the edges of the graph in Figure 7.25 are visited when running Prim’s MST algorithm starting at vertex 3. Show the final MST. One spanning tree is shown in Figure 1. Tree edges are solid lines. Other edges are dashed. To obtain this tree, the edges are added in the following order: { 3 , 2 }, { 2 , 4 }, { 4 , 6 }, { 6 , 1 }, { 6 , 5 }. This spanning tree is not unique. For example, a different spanning tree could be obtained by adding edges in the following order: { 3 , 2 }, { 2 , 4 }, { 2 , 1 }, { 1 , 6 }, { 6 , 5 }.
  2. Problem 7.23, page 222. Consider the collection of edges selected by Dijkstra’s algorithm as the shortest paths to the graph’s vertices from the start vertex. Do these edges form a spanning tree (not necessarily of minimum cost)? Do they form an MST? Explain why or why not. First note that the graph G must be connected in order for it to even have a spanning tree. So we assume the graph is connected.