作者dryman (dryman)
看板EE_DSnP
標題[問題] 一個recursive的問題
時間Fri Dec 4 20:24:12 2009
我想問一個效能的問題
recursive版本:
bool find (const T& x, iterator& pos){
if xxx
return find (x, pos);
}
while版本:
bool find (const T& x, iterator& pos){
while xxx
xxxx
if xxxx
return xxxx
}
假設while版本做一個搜尋要跑O(n)(移動iterator n次)
那麼我的recursive版本會是O(n)還是O(2n)?
不知道一層層return回去會不會也要花時間...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.234
推 ric2k1:while 應該會比 recursive 快一點點 12/04 21:51
→ dryman:thx~ 12/04 23:06