Get this book -> Problems on Array: For Interviews and Competitive Programming
Reading time: 10 minutes | Coding time: 12 minutes
Fleury's algorithm is a simple algorithm for finding Eulerian paths or tours. It proceeds by repeatedly removing edges from the graph in such way, that the graph remains Eulerian.
The steps of Fleury's algorithm is as follows:
- Start with any vertex of non-zero degree.
- Choose any edge leaving this vertex, which is not a bridge (cut edges).
- If there is no such edge, stop.
- Otherwise, append the edge to the Euler tour, remove it from the graph, and repeat the process starting with the other endpoint of this edge.
- Worst case time complexity:
- Average case time complexity:
- Best case time complexity:
- Space complexity:
vector E dfs (v): color[v] = gray for u in adj[v]: erase the edge v-u and dfs(u) color[v] = black push v at the end of e
- Find Eulerian path in a graph