Algorithm 썸네일형 리스트형 [Python] Topological Algorithm을 이용한 순서찾으면서 order possible 찾기. import sys def solve(lines): # if lines is empty, there is no case to solve, so just return nil def add_node(graph, node): """Add a node to the graph.""" if not graph.has_key(node): graph[node] = [0] # 0 = number of arcs coming into this node. def add_arc(graph, fromnode, tonode): """Add an arc to a graph. Can create multiple arcs.""" graph[fromnode].append(tonode) # Update the count of incoming.. 더보기 BFS & DFS BFS Breadth First Search Search Order 1 2 3 4 5 6 7 Worst case performance O( | V | + | E | ) = O(bd) Worst case space complexity O( | V | ) = O(bd) 1. First node in Queue. 2. If Queue is empty, it will stop. 3. If Queue's first element is what we looking for, it will stop. 4. De queue in Queue and En queue all the children. 5.Go back to 2. DFS Depth First Search Search Order 1 2 5 3 4 6 7 1. Fi.. 더보기 이전 1 다음