깊이 우선 탐색 가능한 노드 (Depth First Search Possible Nodes)


문제 설명

깊이 우선 탐색 가능한 노드 (Depth First Search Possible Nodes)

깊이 우선 탐색과 너비 우선 탐색을 수행할 때 주어진 그래프 노드를 방문할 수 있는 가능한 순서를 찾으려고 합니다. 깊이 우선 검색을 하면 FACBDE를, 너비 우선 검색을 하면 FACDEB를 얻었습니다. 이미지를 보려면 여기를 클릭하십시오. 하지만 이것이 정답인지 확실하지 않습니다. 누군가 그것을 확인하고 내 대답이 맞다고 말해 주시겠습니까?


참조 솔루션

방법 1:

I'll waste no time by saying that your BFS and DFS answers do look correct. I'm assuming that the nodes that are given are to be ordered lexicographically. Are you asking this question because you are confused by how each search method works?

Keep in mind that if you get confused, you can always think of BFS as level based search. So, search for all neighbors in respective order. And DFS is more brute forced search. I'd recommend memorizing the psuedo code for each of these search methods. It helps a bunch when your actually coding these things.

BFS:

  • enqueue start node and mark as visited
  • start loop
  • find all neighbors and if not already visited mark as visited
  • add new visited to queue
  • search for goal
  • dequeue ( pop first element off the queue )
  • repeat...

DFS:

  • add start node to stack
    • start loop
  • find first encountered and unvisited neighbor
  • mark as visited
  • add to stack
  • if no neighbors, pop stack
  • repeat...

방법 2:

DFS is correct. BFS should be FACEDB.

When expanding A, the order should be C‑>E‑>D according to the edge number.

(by davidnahmafterShockimmiao)

참조 문서

  1. Depth First Search Possible Nodes (CC BY‑SA 2.5/3.0/4.0)

#depth-first-search #breadth-first-search






관련 질문

깊이 우선 탐색 트리 에지 분류 (Depth first search tree edge classification)

무방향 그래프에서 노드에 대한 최단 경로 찾기 (Finding the shortest path to a node in an undirected graph)

깊이 우선 탐색 가능한 노드 (Depth First Search Possible Nodes)

깊이 우선 검색을 사용하여 트리에서 노드 찾기 (Finding a node in a tree using Depth First Search)

행렬에서 섬을 찾기 위해 DFS 구현 문제 (Problem implementing DFS to find islands in a matrix)

Python에서 재귀 DFS를 효율적으로 구현하는 방법은 무엇입니까? (How to implement recursive DFS in Python efficiently?)

bfs/dfs의 모든 노드를 방문하는 경로를 추적하는 방법 (How to trace the path that visits all nodes in bfs/dfs)

그래프에서 주기를 감지하기 위한 시간 복잡도 (Time complexity for detecting a cycle in a graph)

트리에서 두 노드 사이의 경로를 찾는 방법은 무엇입니까? (How to find the path between 2 nodes in a tree?)

BFS 순회는 완전한 무방향 그래프에서 DFS와 동일합니까? (Is BFS traversal the same as DFS in a Complete Undirected Graph?)

C++에서 깊이 우선 검색 알고리즘을 구현하려고 할 때 읽기 액세스 위반 (read access violation when I tried to implement Depth First Search algorithm in c++)

코스 일정 - 토폴로지 정렬 (Course schedule - Topological sort)







코멘트