Question: This one uses python In this assignment you will write a backtracking algorithm to find an Euler circuit in a graph if one exists or

 This one uses python In this assignment you will write a

backtracking algorithm to find an Euler circuit in a graph if one

This one uses python

In this assignment you will write a backtracking algorithm to find an Euler circuit in a graph if one exists or to identify when there isn't one. As you know, there are simple ways of determining whether a given graph has an Euler circuit, and this should be checked before starting to find an actual Euler circuit. A backtracking algorithm to build an Euler circuit is a recursive algorithm which tries in a systematic way all the possible ways of building a circuit and stops when it manages to build one. More precisely, it can be described as a recursive function which tries to visit the "next" available vertex (i.e. one which is joined to the current vertex by an unvisited edge) until an Euler circuit is found. Visiting the next vertex consists of: 1. Adding the vertex to the circuit 2. Trying to visit each of its available adjacent vertices one by one, each time trying to complete a Euler circuit, until you find one that works, in which case the circuit has been built. An "available adjacent vertex" is one which shares a still unvisited adjacent edge with the vertex being visited. 3. If it was not possible to visit an available adjacent vertex, then the visit of the original vertex failed, and it should be removed from the circuit. This algorithm is expressed recursively, and is also best implemented recursively. If coded carefully, this is not a large function. Implement the following two methods of the Graph class used for finding Euler graphs: findEuler(self) tryvisiting(self, vertex, unvisitedes, walk) The full method signatures of these two methods are specified in the Graph pydocs. You cannot change the method signature of findEuler because it describes the way the function will be used by the testing scripts. However, the second method, try Visiting, is a recursive helper function for findEuler, and will only be called by it. Therefore you may change that function. However, you may also find in practise that this is the best way to structure such a helper function. You may add private fields and methods to the Graph class, should you need them for findEuler, but do not modify the other existing fields and methods of Graph.py and do not modify the classes Test or Walk to support your work. In this assignment you will write a backtracking algorithm to find an Euler circuit in a graph if one exists or to identify when there isn't one. As you know, there are simple ways of determining whether a given graph has an Euler circuit, and this should be checked before starting to find an actual Euler circuit. A backtracking algorithm to build an Euler circuit is a recursive algorithm which tries in a systematic way all the possible ways of building a circuit and stops when it manages to build one. More precisely, it can be described as a recursive function which tries to visit the "next" available vertex (i.e. one which is joined to the current vertex by an unvisited edge) until an Euler circuit is found. Visiting the next vertex consists of: 1. Adding the vertex to the circuit 2. Trying to visit each of its available adjacent vertices one by one, each time trying to complete a Euler circuit, until you find one that works, in which case the circuit has been built. An "available adjacent vertex" is one which shares a still unvisited adjacent edge with the vertex being visited. 3. If it was not possible to visit an available adjacent vertex, then the visit of the original vertex failed, and it should be removed from the circuit. This algorithm is expressed recursively, and is also best implemented recursively. If coded carefully, this is not a large function. Implement the following two methods of the Graph class used for finding Euler graphs: findEuler(self) tryvisiting(self, vertex, unvisitedes, walk) The full method signatures of these two methods are specified in the Graph pydocs. You cannot change the method signature of findEuler because it describes the way the function will be used by the testing scripts. However, the second method, try Visiting, is a recursive helper function for findEuler, and will only be called by it. Therefore you may change that function. However, you may also find in practise that this is the best way to structure such a helper function. You may add private fields and methods to the Graph class, should you need them for findEuler, but do not modify the other existing fields and methods of Graph.py and do not modify the classes Test or Walk to support your work

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!