# S returns the length of the longest typo insert

• Notes
• 6

This preview shows pages 4–6. Sign up to view the full content.

s returns the length of the longest [TYPO: insert “simple” here] path that starts at s . [MISTAKE: I should not have said longest simple path but rather the longest among all the shortest simple paths to other vertices. That’s why you can do it with BFS.] 3 Additional Problems 1. In any connected undirected graph without cycles and with at least two nodes it is possible to remove a node such that the remaining graph is still connected, true or false? Answer TRUE. Such a graph is a tree. After removing a leaf (there must be at least one leaf) the graph remains connected. 2. If we run DFS and BFS on the same undirected connected graph starting at the same node then the resulting spanning trees will have the same number of edges, true or false? Answer TRUE. Let the graph have n nodes. Any of its spanning trees has n - 1 edges, no matter how it was obtained, by DFS, BFS, or any other way. 3. There exist undirected graphs with 3 nodes one of which is labeled s such that DFS and BFS starting at s produce the same spanning tree, true or false? Answer TRUE. Example: a-----s-----b in both cases the spanning tree produced is the graph itself. 4. Every undirected simple graph (i.e., without self-loops and parallel edges) with 4 nodes has 2 or more distinct spanning trees, true or false? Answer FALSE. If the graph is actually a tree than it has only one spanning tree: itself (no matter how many nodes there are). 5. Consider the digraph on eight nodes, labelled 0 through 7, with the 13 directed edges 0->1 6->3 6->5 1->6 7->1 7->3 1->4 4->2 6->0 0->7 3->4 5->2 2->3 Suppose we run the directed DFS algorithm on this digraph starting at node 0. We assume that DFS explores the adjacency list of a node in the numerical order of the labels of the nodes. (a) Draw the rooted tree of discovery edges produced by this algorithm. Answer DFS will explore the nodes and edges in the following order: 4

This preview has intentionally blurred sections. Sign up to view the full version.

0 0->1 1 1->4 4 4->2 2 2->3 3 3->4 1->6 6 6->0 6->3 6->5 5 5->2 0->7 7 7->1 7->3 The nodes and the discovery edges form the following rooted tree 0 / \ / \ / \ 1 7 / \ / \ 4 6 / / 2 5 / 3 (b) The rooted tree that you obtained can be considered as a binary tree if the children of a node are ordered in the numerical order of their labels. List the nodes of this tree in inorder. Answer 3 2 4 1 5 6 0 7 (c) Give an example of a back-edge found by the DFS algorithm. Answer The first back-edge found by the algorithm is 3->4 . It is a back edge because it links the node 3 to a node that is an ancestor of 3 in the spanning tree, namely node 4. (FYI, We call the other edges cross-edges. The last cross-edge found by the algorithm is 7->3 . When the graph is directed, like here, we also have forward-edges. There is no forward-edge in this run of DFS. However, if we also had the edge 4->3 in this graph then it would end up labeled as a forward edge.) 6. We run the DFS algorithm on a connected simple undirected graph (recall that simple means no self-loops and no parallel edges) with m edges and n vertices. How many backedges does the DFS execution find?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern