Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

dfs

# Depth First Search: DFS Algorithm

# 1) Pick any node. 
# 2) If it is unvisited, mark it as visited and recur on all its 
#    adjacent (neighbours) nodes. 
# 3) Repeat until all the nodes are visited

graph= {
    'A' : ['B','C'],
    'B' : ['D', 'E'],
    'C' : ['F'],
    'D' : [],
    'E' : ['F'],
    'F' : []
    }
visited = set() # Set to keep track of visited nodes of graph.

def dfs(visited, graph, node):  #function for dfs 
    if node not in visited:
        ''' 
        We start with A
        Then B
        Then D
        Then E
        Then F
        Then C
        A -> B -> D -> E -> F -> C
        '''
        print(node)
        # added to visited to avoid visit the node twice 
        visited.add(node)
        for neighbour in graph[node]:
            ''' 
            * Neighbour of A : B and C but first visit B
            * Then neighbour of B : D and E but first visit D 
            * Then neighbour of D : doesn't have neighbour then backtrack to the neighbour
                of the previous node (B) which is E
            * Then neighbour of E : F
            * Then neighbour of F : doesn't have neighbour then backtrack to the neighbour 
                of the previous node E but doesn't have other neighbour except F which is visited
                So backtracking again to B and B also doesn't have nodes not visited 
                So backtracking again to A: C not visited YAY!
            '''
            dfs(visited, graph, neighbour)
    
print(dfs(visited, graph, 'A'))
Comment

dfs

@override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(40.0),
          child: ClipShadowPath(
            clipper: _MyClipper(100),
            shadow: const Shadow(
              blurRadius: 15,
              color: Colors.grey,
              offset: Offset(0, 10),
            ),
            child: SizedBox(
              height: 400,
              child: Container(
                color: Colors.white,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: const [
                    Spacer(),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class _MyClipper extends CustomClipper<Path> {
  final double space;

  _MyClipper(this.space);

  @override
  Path getClip(Size size) {
    final path = Path();
    final halfWidth = size.width / 2;
    final halfSpace = space / 2;
    final curve = space / 6;
    final height = halfSpace / 1.4;
    path.lineTo(halfWidth - halfSpace, 0);
    path.cubicTo(halfWidth - halfSpace, 0, halfWidth - halfSpace + curve,
        height, halfWidth, height);

    path.cubicTo(halfWidth, height, halfWidth + halfSpace - curve, height,
        halfWidth + halfSpace, 0);

    path.lineTo(size.width, 0);
    path.lineTo(size.width, size.height);
    path.lineTo(0, size.height);
    path.close();

    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) => true;
}
Comment

PREVIOUS NEXT
Code Example
Python :: python takes 2 positional arguments but 3 were given 
Python :: add Elements to Python list Using append() method 
Python :: args in python 
Python :: python package install 
Python :: cmap seaborn 
Python :: comment all selected lines in python 
Python :: second highest value in list python 
Python :: python transpose 
Python :: custom permission class django rest framework 
Python :: gui in python 
Python :: oops python 
Python :: python size of list 
Python :: python search list 
Python :: python iterrows 
Python :: numpy.dot 
Python :: how to change datatype of column in pandas 
Python :: map python 
Python :: how to make a modulo in python 
Python :: spreadsheet worksheet counter 
Python :: python list of paths 
Python :: how do you make plot show with matplotlib ion method 
Python :: Python - Comment supprimer Commas de la corde 
Python :: pandas cummax 
Python :: how to print on same line python 
Python :: does pygame work on python 3.10.1 
Python :: flask example 
Python :: plotly change marker symboly sequence 
Python :: add service files in setup.py ROS2 
Python :: python how to be able to use any python file you made on all projects 
Python :: sort vs sorted python 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =