Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Minor comments updated
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiHarsh committed Mar 26, 2018
1 parent e7ec5d6 commit 618efe4
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/sage/graphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6739,18 +6739,19 @@ def ear_decomposition(self):
An ear of an undirected graph `G` is a path `P` where the two endpoints
of the path may coincide (i.e., form a cycle), but where otherwise no
repetition of edges or vertices is allowed, so every internal vertex
repetition of edges or vertices is allowed, so every internal vertex
of P has degree two in `P`.
An ear decomposition of an undirected graph `G` is a partition of its
set of edges into a sequence of ears, such that the one or two endpoints
of each ear belong to earlier ears in the sequence and such that the
internal vertices of each ear do not belong to any earlier ear.
of each ear belong to earlier ears in the sequence and such that the
internal vertices of each ear do not belong to any earlier ear.
For more information, see the
:wikipedia:`Ear_decomposition`.
This method implements the linear time algorithm presented in [Sch2013]_.
This method implements the linear time algorithm presented in
[Sch2013]_.
INPUT:
Expand Down Expand Up @@ -6804,7 +6805,6 @@ def ear_decomposition(self):
sage: g.add_edge(u, u)
sage: g
Bull graph: Looped multi-graph on 5 vertices
sage: h = copy(g)
sage: h = g.to_simple()
sage: g.ear_decomposition() == h.ear_decomposition()
True
Expand All @@ -6828,7 +6828,7 @@ def ear_decomposition(self):
# Dfs traversal in graph.
seen = set()

# Boolean dict to mark vertices as visited or unvisited in
# Boolean dict to mark vertices as visited or unvisited in
# Dfs tree traversal.
traversed = set()

Expand Down Expand Up @@ -6856,26 +6856,27 @@ def DFS(v):
Depth first search step from vertex v.
"""

# make v are visited, update it's time of visited and value
# make v are visited, update its time of visited and value
seen.add(v)
dfs_order.append(v)

# Traverse though all the neighbor vertices of v
for u in self.neighbor_iterator(v):
# if any neighbor is not visited, enter
if u not in seen:
# Set the parent of u in DFS tree as v and continue exploration
# Set the parent of u in DFS tree as v and
# continue exploration
parent[u] = v
DFS(u)

# Traverse() : Function that use G-T(non -tree edges) to find cycles and
# chains by traversing in DFS tree.
# Traverse() : Function that use G-T (non-tree edges) to find cycles
# and chains by traversing in DFS tree.
def traverse(start, pointer):
# Make the firt end of non-tree edge visited
traversed.add(start)
chain = [start]

# Traverse DFS Tree of G and print all the not visited vertices.
# Traverse DFS Tree of G and print all the not visited vertices
# Appending all the vertices in chain
while True:
chain.append(pointer)
Expand All @@ -6888,11 +6889,12 @@ def traverse(start, pointer):
# Perform ear decomposition on each connected component of input graph.
for v in vertices:
if v not in seen:
# start the depth first search from first vertex
# Start the depth first search from first vertex
DFS(v)
value = {u:i for i,u in enumerate(dfs_order)}

# Traverse all the non Tree edges, according to depth first traversal
# Traverse all the non Tree edges, according to
# depth first traversal
for u in dfs_order:
for neighbor in self.neighbor_iterator(u):
if value[u] < value[neighbor] and u != parent[neighbor]:
Expand Down

0 comments on commit 618efe4

Please sign in to comment.