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

Short Answer

Expert verified

In the given problem, applieddepth-first search where the order of traverse isABCFEIDGH .

In order first we get the pre vertices of all and then get post vertex of the graph. Which are mentioned in the above diagram. A(1,16),B(2,11),C(3,10),F(4,9),E(5,6),I(7,8),D(13,18),G(14,17),H(15,16)

Step by step solution

01

Properties of DFS

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

Some properties ofdepth-first search are as follows:

  1. Using DFT we can verify that the graph is connected or not it means it detects the cycle present in the graph or not.
  2. We can find out the number of connected components by using depth-first search.
  3. Here we are using stack as a data structure.

The time complexity of list is O(V+E).

The time complexity of matrix isO(V2) .

It contains various edge they aretree edge, forward edge, back edge, or cross edge all the edges are explain below:

Tree edge: The graph obtained by traversing while using depth first search is called its tree edge.

Forward edge: the edge(u,v)where u is descendant and it is not part of depth first search is called forward edge.

Back edge: the edge (u,v)where u is ancestor and it is not part of depth first search is called forward edge.

02

Trace the graph

While traversing the graph by depth-first search firstly we get the vertices A, from A there are two options B and E and through A we must go to B.

From vertices B we have again two options they are C and E take C as our next vertices then F then by word depth first search going through node E, as there from F there are again two options they are E and I as mentioned in question traverse alphabetically so here after E, F comes that’s why go to F. and from F go to E and at last visit at I. also it contains a different graph that is contain nodes D,G,H. start from the source node D going in a alphabetic orderdepth first searchtraverse G and then H. here in the diagram the edge AB in black color is the main edge called tree edge.

The edge in blue color for example edge AF is called back edge, and the edge BE is called as forward edge.

Now, draw the graph traverse by depth-first search.


Hence, after applying depth-first search where the order of traverse is ABCFEIDGH.

03

Write the vertices

The tree edges are in the graph after traversing AB,BC,CF,EF,FI,DG,GH

And the back edges are as follows AE, BE and DH.

The pre and post-number of each vertex are given as,A(1,12) where

1 is pre vertex and 12 is post vertex.

In order first we get the pre vertices of all and then get post vertex of the graph. Which are mentioned in the above diagram.A(1,16),B(2,11),C(3,10),F(4,9),E(5,6),I(7,8),D(13,18),G(14,17),H(15,16)

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 Vaia!

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

Two paths in a graph are called edge-disjointif they have no edges in common. Show that in any undirected graph, it is possible to pair up the vertices of odd degree and find paths between each such pair so that all these paths are edge-disjoint.

You are given tree T=(V,E) along with a designated root node rV. The parent of any node Vr, denoted p(V), is defined to be the node adjacent to v in the path from r to v . By convention, p(r)=r. For k>1, define pk(v)pk-1(pv)andp1(v)=p(v)(so pk(v)is the k th ancestor of v ). Each vertex v of the tree has an associated non-negative integer label l(v). Given a linear-time algorithm to update the labels of all the vertices T according to the following rule: lnew(v)=l(plvv).

You are given a tree T=(V,E) (in adjacency list format), along with a designated root node rV. Recall that u is said to be an ancestor of v in the rooted tree if the path from r to v in T passes through u.

You wish to reprocess the tree so that queries of the form “is u an ancestor v?” can be answered in constant time. The pre-processing itself should take linear time. How can this be done?

Question:Undirected vs. directed connectivity.

(a) Prove that in any connected undirected graph G =(V , E)there is a vertexvV whose removal leaves G connected. (Hint: Consider the DFS search tree for G.)

(b) Give an example of a strongly connected directed graph G(V ,E)such that, for everyvV, removing v from G leaves a directed graph that is not strongly connected.

(c) In an undirected graph with two connected components it is always possible to make the graph connected by adding only one edge. Give an example of a directed graph with two strongly connected components 0 such that no addition of one edge can make the graph strongly connected.

Either prove or give a counterexample: if {u,v}is an edge in an undirected graph, and during depth-first search (u)<post (v), then vis an ancestor of uin the DFS tree.

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.

Sign-up for free