Skip to content

Commit

Permalink
Merge pull request gzc#148 from ravgill/master
Browse files Browse the repository at this point in the history
Fixed solution for 22.1.8
  • Loading branch information
Zhenchao Gan authored Jul 20, 2017
2 parents 631b290 + 397eecc commit 83c8578
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 4 additions & 6 deletions C22-Elementary-Graph-Algorithms/22.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ Actually, the problem can also be solved by computing the longest shortest path
Let G = (V, E) be a connected, undirected graph. Give an O(V + E)-time algorithm to compute a path in G that traverses each edge in E exactly once in each direction. Describe how you can find your way out of a maze if you are given a large supply of pennies.

### `Answer`
Euler path problem.

**欧拉路径**:图中经过每条边一次且仅一次的路径;
We can perform a DFS like procedure where each edge has a state among the following: never visited, visited once, visited twice. We never visit an edge that has been visited twice. To ensure we explore all edges we will prioritize edges that have never been traversed over edges that have been traversed once. This way, we will explore edges the second time during backtracking phase of DFS.

You can reference [here](https://github.com/gzc/sgu/blob/master/100-199/101.cpp)
Every time we visit an unexplored edge(u, v) we add (u, v) to our path.
Every time we backtrack from vertex v to vertex u we add (v, u) to our path.

一个无向图如果有一个欧拉路径,需要满足几个条件: 它的奇数度节点数要么是0要么是2(此时这两个点只能作为欧拉路径的起点和终点)

If an underected graph has an Euler path, it must satisfy : its odd dgree node is either 0 or 2.(Under such circumstance, the odd degree are start node and end node).
Given a large supply of pennies, we will use pennies to mark state of an edge as suggested above. We put a penny down on each edge every time we travel it and we will never travel an edge with already two pennies placed. Alternatively we can use absence of penny, head face up, tail face up for keeping track of edges that haven't been explored, explored once and explored twice respectively.

***
Follow [@louis1992](https://github.com/gzc) on github to help finish this task.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Solutions to *Introduction to Algorithms* by Charles E. Leiserson, Clifford Stei
27. [imbrobits](https://github.com/imbrobits)
28. [zhanglanqing](https://github.com/zhanglanqing)
29. [tushar-rishav](https://github.com/tushar-rishav)
30. [ravgill](https://github.com/ravgill)

If I miss your name here, please pull a request to me to fix.

Expand Down

0 comments on commit 83c8578

Please sign in to comment.