/*! 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} Q10E Rewrite the explore procedure (F... [FREE SOLUTION] | 91Ó°ÊÓ

91Ó°ÊÓ

Rewrite the explore procedure (Figure 3.3) so that it is non-recursive (that is, explicitly use a stack). The calls to pre visit and post visit should be positioned so that they have the same effect as in the recursive procedure.

Short Answer

Expert verified

The recursive procedure is proved.

Step by step solution

01

Step 1: Depth-first search in an undirected graph

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 the downward direction one by one.

Some properties ofdepth-first search are as follows:

  1. Using DFT we can verify whether 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 usingdepth-first search.
  3. Here we are using the stack as a data structure.

The time complexity of the list isOV+E.

The time complexity of the matrix isOV2.

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

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

Forward edge: the edgeu,vwhere is descendant and it is not part of depth first search is called forward edge.

Back edge: the edge u,vwhere is ancestor and it is not part of depth first search is called back edge.

02

Proving the algorithm

The calls to pre visit and positivist should be positioned so that they have the same effect as in the recursive procedure this algorithm is shown below:

Procedure exploreG,u.

G,u

S = ( emptystack)

pushS,u

While S is not empty

v = top(S)

If not visited [ v ]:

visited [ v ] = true

previsit (v)

If there is an edge, then

v,wl^E

withvisited {w] = false:

push(S,w)

else;

Now, the node at the top of the stack.

pop[s]

postvisit [v]

The explore procedure of non-recursive, explicitly use a stack. The calls to previsit and postvisit positioned so that they have the same effect as in the recursive procedure is proved.

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

Perform depth-first search on each of the following graphs; whenever there’s 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.

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.

The police department in the city of Computopia has made all streets one-way. The mayor contends that there is still a way to drive legally from any intersection in the city to any other intersection, but the opposition is not convinced. A computer program is needed to determine whether the mayor is right. However, the city elections are coming up soon, and there is just enough time to run a linear-time algorithm.

a) Formulate this problem graph-theoretically, and explain why it can indeed be solved in linear time.

(b) Suppose it now turns out that the mayor’s original claim is false. She next claims something weaker: if you start driving from town hall, navigating one-way streets, then no matter where you reach, there is always a way to drive legally back to the town hall. Formulate this weaker property as a graph-theoretic problem, and carefully show how it too can be checked in linear time.

Give an efficient algorithm which takes as input a directed graph G(V,E)and determines whether or not there is a vertexs∈V from which all other vertices are reachable.

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

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.