/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Q2E Perform depth-first search on ea... [FREE SOLUTION] | 91影视

91影视

Perform depth-first search on each of the following graphs; whenever there鈥檚 a choice of vertices, pick the one that is alphabetically first. Classify each edge as a tree edge, forward edge, back edge, or cross edge, and give the pre and post number of each vertex.

Short Answer

Expert verified

(a) Order of DFS traversal: ABCDHGFE

Tree edges: AB,BC,CD,DH,GH,FG,FE

Forward edges:AF,BE

Back edge: FG,EG,ED,DB

Pre and Post order are: A(1,16),B(2,15),C(3,14),D(4,13),H(5,12),G(6,11),F(7,10),E(8,9)

,

(b) Order of DFS traversal: ABFCDEHG

Tree edges: AB,AH,HG,BF,FC,DE

Forward edges: FE

Back edge: GA,CB

Cross edge: DC,GF,GB

Pre and Post order are: localid="1657775037924" A(1,16),B(2,11),C(4,5),D(6,9),E(7,8),F(3,10),G(13,14),H(12,15)

Step by step solution

01

Step 1: Depth First Search Graph Traversal

Depth First Search (DFS) is an application of graph traversal. It traverses the node downwards and uses the stack as a data structure through this it traverses all vertices in downward direction one by one.

A graph contains various edges. They are:tree edge, forward edge and back edge. The graph obtained by traversing while using depth first search is called its tree edge. The edge (u,v)where u is descendant and it is not part of depth first search is called forward edge. The edge(u,v) where u is ancestor and it is not part of depth first search is called forward edge.

02

Traverse the graph (a) by depth first search.

(a)

While traversing the graph bydepth-first search, the vertex A is traversed first. From A there are two options B and F and through A traversal is done to B.

From vertex B two options are C and E. Take E as the next vertex then D then using depth first search, go through node H, G and last traverse F. Figure showing graph traversal by depth first search is:

Edge AB in black color is the main edge called tree edge. The edge in blue color for edge AF is called back edge and the edge BE is called as forward edge.

Here the tree edges for the given graph are AB,BC,CD,DH,GH,FG,FE. The forward edges are AF,BE. And the back edge of the graph is FG,EG,ED,DB.The tree edges of the given graph are localid="1657775173067" AB,AH,HG,BF,FC,DE.The forward edge is FE. The back edges are GA,CBand the cross edge of the graph is DC,GF,GB. Hence, after applying depth-first search where the order of traversal is ABCDHGFE .

The pre and post number of each vertex are given as, A1,16 where 1 is pre vertex and 16 is post vertex. First the pre vertex is obtained and then post vertex of the graph is obtained. The final sequence of the pre and post order are A(1,16),B(2,15),C(3,14),D(4,13),H(5,12),G(6,11),F(7,10),E(8,9).

Hence, pre and post numbers of each vertex are localid="1657775094839" A(1,16),B(2,15),C(3,14),D(4,13),H(5,12),G(6,11),F(7,10),E(8,9)and the order of DFS traversal is ABCDHGFE .

03

Traverse the graph (b) by depth first search.

(b)

Figure showing graph traverse by depth first search is

In this graph, according to depth first search start from the node A, there are two vertices that are linked with A they are B or H but as mentioned in the question that give preference of vertices by their alphabetic order. Hence, after this visit B. From B there is a direct connection with F. So, the next node in this path is F then again F is connected with two nodes that are C and D . Here by alphabetical order traversal, first C is traversed then from C there is no other edge for traversing then go to the back edge which is back track F to D . After D , traverse the other nodes in a same way that are E,G,F .

Blue color in the graph shows cross edge. Black color shows tree edge of the traversal and the red edge shows back edge and the edge in the green shows forward edge.

Pre and post number of the vertex A given is A1,16 where 1 is pre vertex and 16 is the post vertex. Similarly, the pre and post number of each vertex of the graph is obtained.

Hence, pre and post numbers of each vertex are A(1,16),B(2,11),C(4,5),D(6,9),E(7,8),F(3,10),G(13,14),H(12,15)and the order of DFS traversal is ABFCDEHG.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with 91影视!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Let S be a finite set. A binary relation on S is simply a collection R of ordered pairs(x,y)SS. . For instance, S might be a set of people, and each such pair (x,y)R might mean 鈥 x knows y 鈥.

An equivalence relationis a binary relation which satisfies three properties:

  • Reflexivity: localid="1659006645990" (x,y)R for all XS
  • Symmetry: If (x,y)R then (y,x)R
  • Transitivity: if (x,y)R and (y,z)R then localid="1659006784500" (x,Z)R

For instance, the binary relation 鈥渉as the same birthday as鈥 is an equivalence relation, whereas 鈥渋s the father of鈥 is not, since it violates all three properties.

Show that an equivalence relation partition set S into disjoint groups S1,S2,,Sk (in other words, S=S1S2SkandSiSj=forallij ) such that:

  • Any two members of a group are related, that is, (x,y)R for any localid="1659006702579" (x,y)Si, for any i .
  • Members of different groups are not related, that is, for all ij, for all localid="1659006762355" xSi andySi, we have (x,Z)R.

(Hint: Represent an equivalence relation by an undirected graph.)

The chapter suggests an alternative algorithm for linearization (topological sorting), which repeatedly removes source nodes from the graph (page 101). Show that this algorithm can be implemented in linear time.

Infinite paths.Let G=(V,E) be a directed graph with a designated 鈥渟tart vertex鈥 sV,asetVGV, a set of 鈥済ood鈥 vertices, and a set VBV of 鈥渂ad鈥 vertices. An infinite trace of is an infinite sequence of vertices viV such that (1)v0=s, and (2) for all i0, (vi,vi+1)E. That is, p is an infinite path in G starting at vertex s. Since the setV of vertices is finite, every infinite trace of Gmust visit some vertices infinitely often.

  1. If p is an infinite trace, let Inf(p)V be the set of vertices that occur infinitely often in p. Show that Inf(p) is a subset of a strongly connected component of G.
  2. Describe an algorithm that determines if role="math" G has an infinite trace.
  3. Describe an algorithm that determines if G has an infinite trace that visits some good vertex in VG infinitely often.
  4. Describe an algorithm that determines if role="math" localid="1659627728759" G has an infinite trace that visits some good vertex in VG infinitely often, but visits no bad vertex in VB infinitely often.

In an undirected graph, the degreed(u) of a vertex u is the number of neighbours u is the number of neighbors u has, or equivalently, the number of edges incident upon it. In a directed graph, we distinguish between the indegreedin(u), which is the number of edges into u, and the outdegreedout(u), the number of the edges leaving u.

(a) Show that in an undirected graph, role="math" localid="1658908755010" uevd(u)=2|E|

(b) Use part (a) to show that in an undirected graph, there must be an even number of vertices whose degree is odd.

(c) Does a similar statement hold for the number of vertices with odd indegree in a directed graph?

Suppose a CS curriculum consists of n courses, all of them mandatory. The prerequisite graph G has a node for each course, and an edge from course v to course w if and only if v is a prerequisite for w. Find an algorithm that works directly with this graph representation, and computes the minimum number of semesters necessary to complete the curriculum (assume that a student can take any number of courses in one semester). The running time of your algorithm should be linear.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.