

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 3
This page cannot be seen from the preview
Don't miss anything!
(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.
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.