读书人

求怎么正确解答此数据结构题? 关于DFS

发布时间: 2014-04-30 17:08:22 作者: rapoo

求如何正确解答此数据结构题? 关于DFS算法的。
There is given an undirected graph G = (V, E) and a distinguished node s, called a source. Recall the recursive de?nition of DFS search from the source s.
1.Write a pseudo-code of this recursive version of DFS.
2.Provide and justify two recursive formulas: on the number of operations (i.e., reading/writing to memory, comparisons, updates, etc.), and on the number of additional memory allocated by the recursive process.
3.Solve the above formulas in order to obtain accurate asymptotic upper bounds.

第一问想必是这样的:
DFS(s):
Mark s as "Explored" and add s to R
For each edge (s, v) incident to s
If v is not marked "Explored" then
Recursively invoke DFS(v)
Endif
Endfor
第二问我觉得就是O(m+n), 额外内存使用该是:O(n)。但我没见过这么出题的,不知道怎么解释。
但是第三问似乎还是O(m+n),或者是把忽略的常数算进去?把额外内存使用算进去?O(2m+2n)?

有没有人能解答我的疑问?谢了先!
[解决办法]
第二问要你写出复杂度的递归式,并证明它是对的。
第三问是求解刚才那个递归式。
[解决办法]
asymptotic。所以只要O()就可以了。

读书人网 >软件架构设计

热点推荐