Foo(A,f,l)
**Precondition: A[f ...l] is an array of integers, f,l are two naturals ≥ 1 with f ≤ l.
if (f = l) then
return A[f]
else
m ← floor of((f+l)/2)
return min(Foo(A,f,m), Foo(A,m + 1,l))
end if
糾正我,如果我錯了,但我認爲這段代碼返回數組的最小整數。但是,我怎樣才能找出用陣列A描述時間複雜性的遞歸關係?你能指導我解決方案,以便我能理解嗎?我甚至不知道從哪裏開始。如何編寫僞代碼的遞歸關係?
取A,f,l的一些示例值並畫出所做的調用,即完全重複。你會看到在每次通過時,搜索空間減半。複雜性是對數的。 – Rishav
有了這個前提'f <=',你不能確保它在你的內部調用中實現。此外,它似乎是一個無用的先決條件,也許你應該刪除它。你既不能確保'm> = 1' –
看看這個[問題](http://stackoverflow.com/questions/3255/big-o-how-do-you-calculate-approximate-it) – DarthRubik