/*! 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} Q1E Perform a depth-first search on ... [FREE SOLUTION] | 91影视

91影视

Perform a depth-first search on the following graph; whenever there鈥檚 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鈥檚 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 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

As in the previous problem, you are given a binary tree T=(V,E) with designated root node. In addition, there is an array x[.]with a value for each node in V Define a new array z[.]as follows: for each uV,

z[u]=the maximum of the x-values associated with u鈥檚 descendants.

Give a linear-time algorithm that calculates the entire z-array.

A bipartite graph is a graph G=(V,E)whose vertices can be partitioned into two sets (V=V1V2andV1V2=) such that there are no edges between vertices in the same set (for instance, if , then there is no edge between and ).

(a) Give a linear-time algorithm to determine whether an undirected graph is bipartite.

(b) There are many other ways to formulate this property. For instance, an undirected graph is bipartite if and only if it can be colored with just two colors. Prove the following formulation:

an undirected graph is bipartite if and only if it contains no cycles of odd length.

(c) At most how many colors are needed to color in an undirected graph with exactly one odd length?

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 鈥渋s u an ancestor v?鈥 can be answered in constant time. The pre-processing itself should take linear time. How can this be done?

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).

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?

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.