📜  门| GATE-CS-2017(套装2)|问题 22

📅  最后修改于: 2021-09-26 04:33:07             🧑  作者: Mango

呼吸优先搜索(BFS)已使用队列数据结构实现。

g2017_15

以下哪一项是访问上图中节点的可能顺序。
(一) MNOPQR
(B) NQMPOR
(C) QMNROP
(D) POQNMR答案: (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"

这个问题的测验