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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count number of times each Edge appears in all possible paths of a given Tree
- Find maximum number of edge disjoint paths between two vertices
- Bridges in a graph
- Maximum number of bridges in a path of a given graph
- Maximize number of nodes which are not part of any edge in a Graph
- Find the maximum component size after addition of each edge to the graph
- Number of Unicolored Paths between two nodes
- Check if given path between two nodes of a graph represents a shortest paths
- Count of Root to Leaf Paths consisting of at most M consecutive Nodes having value K
- Minimum Cost using Dijkstra by reducing cost of an Edge
- Shortest Path in a weighted Graph where weight of an edge is 1 or 2
- Check if removing a given edge disconnects a graph
- Delete Edge to minimize subtree sum difference
- Minimum edge reversals to make a root
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Program to Calculate the Edge Cover of a Graph
- Tree, Back, Edge and Cross Edges in DFS of Graph
- Edge Coloring of a Graph
- Shortest path from source to destination such that edge weights along path are alternatively increasing and decreasing
- Product of minimum edge weight between all pairs of a Tree
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.