Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

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

Design a linear-time algorithm which, given an undirected graph G and a particular edge ein it, determines whetherGhas a cycle containing.

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?

For each node in an undirected graph, let twodegreeube the sum of the degrees of’s neighbors. Show how to compute the entire array of two degree. values in linear time, given a graph in adjacency list format

The reverse of a directed graph G = (V,E) is another directed graphGR=(V,ER) on the same vertex set, but with all edges reversed that is,ER={(v,u):(u,v)E} . Give a linear-time algorithm for computing the reverse of a graph in adjacency list format.

In the 2SAT problem, you are given a set of clauses, where each clause is the disjunction (OR) of two literals (a literal is a Boolean variable of or the negation of a Boolean variable). You are looking for a way to assign a valuetrueorfalseto each of the variables so that all clauses are satisfied- that is, there is at least one true literal in each clause. For example, here’s an instance of 2SAT:

x1x2¯x1¯x3¯x1x2x3¯x4x1¯x4

This instance has a satisfying assignment: set x1,x2,x3, and x4 totrue, false, false,andtrue,respectively.

  1. Are there other satisfying truth assignments of this 2SAT formula? If so, find them all.
  2. Give an instance of 2SAT with four variables, and with no satisfying assignment.

The purpose of this problem is to lead you to a way of solving 2SAT efficiently by reducing it to the problem of finding the strongly connected components of a directed graph. Given an instance l of 2SAT with n variables and m clauses, construct a directed graph GI=V,E as follows.

  • GIhas 2nnodes, one for each variable and its negation.
  • GIhas 2m edges: for each clause αβof l (where α,βare literals), G1has an edge from the negation of α to β, and one from the negation ofβ to α.

Note that the clause αβis equivalent to either of the implications α¯β or β¯α. In this sense, data-custom-editor="chemistry" GI records all implications in l .

(C). Carry out this construction for the instance of 2SAT given above, and for the instance you constructed in (b).

(d). Show that if GI has a strongly connected component containing both x and X¯ for some variable x , then l has no satisfying assignment.

(e). Now show the converse of (d): namely, that if none of GI’s strongly connected components contain both a literal and its negation, then the instance l must be satisfiable.(Hint: Assign values to the variables as follows: repeatedly pick a sink strongly connected component of GI. Assign valuetrueto all literals in the sink, assignfalseto their negations, and delete all of these. Show that this ends up discovering a satisfying assignment.)

(f). Conclude that there is a linear-time algorithm for solving 2SAT.

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