There are n nodes and m bridges in between these nodes. Print the possible path through each node using each edges (if possible), traveling through each edges only once.
Input : [[0, 1, 0, 0, 1], [1, 0, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 0, 0], [1, 0, 0, 0, 0]] Output : 5 -> 1 -> 2 -> 4 -> 3 -> 2 Input : [[0, 1, 0, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 1], [1, 1, 1, 0, 0], [1, 0, 1, 0, 0]] Output : "No Solution"
It is one of the famous problems in Graph Theory and known as problem of “Seven Bridges of Königsberg”. This problem was solved by famous mathematician Leonhard Euler in 1735. This problem is also considered as the beginning of Graph Theory.
The problem back then was that: There was 7 bridges connecting 4 lands around the city of Königsberg in Prussia. Was there any way to start from any of the land and go trough each of the bridges once and only once? Please see these wikipedia images for more clarity.
Euler first introduced graph theory to solve this problem. He considered each of the lands as a node of a graph and each bridge in between as an edge in between. Now he calculated if there is any Eulerian Path in that graph. If there is an Eulerian path then there is a solution otherwise not.
Problem here, is a generalized version of the problem in 1735.
Below is the implementation :
2-0 0-1 1-2 2-3 1-0 0-2 2-3 3-1 1-0 0-2
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find maximum number of edge disjoint paths between two vertices
- Maximize number of nodes which are not part of any edge in a Graph
- Number of Unicolored Paths between two nodes
- Check if given path between two nodes of a graph represents a shortest paths
- Bridges in a graph
- Maximum number of bridges in a path of a given graph
- Edge Coloring of a Graph
- Minimum edge reversals to make a root
- Program to Calculate the Edge Cover of a Graph
- Delete Edge to minimize subtree sum difference
- Check if removing a given edge disconnects a graph
- Remove all outgoing edges except edge with minimum weight
- Tree, Back, Edge and Cross Edges in DFS of Graph
- Find weight of MST in a complete graph with edge-weights either 0 or 1
- Shortest Path in a weighted Graph where weight of an edge is 1 or 2
- Add and Remove Edge in Adjacency List representation of a Graph
- Product of minimum edge weight between all pairs of a Tree
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Count of node sequences of length K consisting of at least one black edge
- Maximum cost path in an Undirected Graph such that no edge is visited twice in a row
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.