Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Bertrand NÉRON
algo
Commits
07984a8e
Verified
Commit
07984a8e
authored
Sep 02, 2019
by
Bertrand NÉRON
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✏
add docstring
and fix hit typing
parent
851bbb96
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
Graph/graph/graph.py
Graph/graph/graph.py
+19
-6
No files found.
Graph/graph/graph.py
View file @
07984a8e
import
itertools
from
typing
import
List
,
Optional
from
typing
import
Generator
,
Optional
class
NDGraph
:
...
...
@@ -78,9 +78,16 @@ class Node:
return
n
def
DFS
(
graph
:
Graph
,
node
:
Node
)
->
List
[
Node
]:
def
DFS
(
graph
:
Graph
,
node
:
Node
)
->
Generator
[
Node
]:
"""
Depth First Search
**D**epth **F**irst **S**earch.
We start the path from the node given as argument,
This node is labeled as 'visited'
The neighbors of this node which have not been already 'visited' nor 'to visit' are labelled as 'to visit'
We pick the last element to visit and visit it
(The neighbors of this node which have not been already 'visited' nor 'to visit' are labelled as 'to visit').
on so on until there no nodes to visit anymore.
:param graph:
:param node:
:return:
...
...
@@ -95,10 +102,16 @@ def DFS(graph: Graph, node: Node) -> List[Node]:
yield
n
def
BFS
(
graph
:
Graph
,
node
:
Node
)
->
List
[
Node
]:
def
BFS
(
graph
:
Graph
,
node
:
Node
)
->
Generator
[
Node
]:
"""
Breadth First search
**B**readth **F**irst **s**earch
We start the path from the node given as argument,
This node is labeled as 'visited'
The neighbors of this node which have not been already 'visited' nor 'to visit' are labelled as 'to visit'
we pick the **first** element of the nodes to visit and visit it.
(The neighbors of this node which have not been already 'visited' nor 'to visit' are labelled as 'to visit')
on so on until there no nodes to visit anymore.
:param graph:
:param node:
:return:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment