Verified Commit 07984a8e authored by Bertrand  NÉRON's avatar Bertrand NÉRON
Browse files

add docstring

and fix hit typing
parent 851bbb96
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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment