呼吸优先搜索(BFS)已使用队列数据结构实现。
以下哪一项是访问上图中的节点的可能顺序。
(A) MNOPQR
(B) NQMPOR
(C) QMNROP
(D) POQ核磁共振答案: (D)
说明:在BFS中,我们打印一个起始节点,然后打印它的相邻节点,然后相邻的相邻节点,依此类推。
Option A : MNOPQR Wrong
We cannot visit "O" before "R" as we start from "M".
Note that "O" is adjacent of adjacent for "M" and
"R" is adjacent of "M".
Option B : NQMPOR Wrong
We cannot visit "P" before "O" as we start from "N".
Note that "P" is adjacent of adjacent for "N" and
"O" is adjacent.
Option C : QMNROP Wrong
We cannot visit "R" before "O" as we start from "Q".
Note that "R" is adjacent of adjacent for "Q" and
"O" is adjacent of "Q"
Option D : POQNMR Right
We visit "P", then its adjacent "O", "Q" and "N"
Finally we visit adjacent of adjacent "M" and "R"
这个问题的测验