IT討論區(56) I巴條數何時了

1001 回覆
4 Like 0 Dislike
2019-02-09 23:46:03
2019-02-09 23:48:21
2019-02-10 00:59:12
黎緊呢年mobile app developer 搵唔搵到食
2019-02-10 02:06:16
O(1) precompute 後查表外仲有咩方法?
2019-02-10 02:12:53
2019-02-10 10:26:47
你咁算唔算自問自答?
2019-02-10 11:02:13
Recursion time係O(2^n), space O(n)
O(n)用dp/loop
O(log n)用matrix multiplication?
O(1)用formula
不過如果係我interview會用O(n) loop計,最快寫到
2019-02-10 11:18:09
O(log n) -> Memoization
2019-02-10 11:21:59
O(1) 唔答
2019-02-10 11:31:26
Memoization即是dp,應該每個數都要計過一次,所以O(n)
O(log n)係要用matrix multiplication or formula derived from it
2019-02-10 11:35:17
O(1)有條直接揾到nth fib嘅formula
2019-02-10 12:01:32
又要比人壓價
2019-02-10 12:19:36
No, my old post in hkgolden does not cover O(1) Fibonacci. I don’t think you can do O(1) without precomputation.
2019-02-10 12:21:21
Not really. you can do O(log n) time and O(1) space using matrix multiplication with memorizing anything.
2019-02-10 12:23:54
What is the time complexity for evaluating the close for of Fibonacci numbers? How long does it take to compute a^n for an arbitrary n?
2019-02-10 12:51:04
I meant without memorizing, sorry
2019-02-10 13:20:25
屌😂
2019-02-10 13:21:11
U can if you consider math is a O(1) oracle, which is not a really bad consideration as pow is slow anyway
2019-02-10 13:26:01
Math.pow我記得係O(1)
2019-02-10 13:26:42
You cannot consider maths to be O(1). Otherwise there is no point in studying multiplication algorithms for example. You can only treat basic arithmetic operations for small numbers to be O(1) like 64 bit. Multiplying two really big numbers is not O(1) for example.
2019-02-10 13:28:49
咁O(1)就無solution了,最快是O(log n)
2019-02-10 13:29:09
Ok 我應該講清楚 個function declaration係int f(int n)
因為我個時係比人問呢個形式 而唔係比人問bigint
2019-02-10 13:40:36
Even if you restrict the range to be 64 bit, pow() may not be O(1). If you compute pow() using a Taylor series approximation with fixed number of terms, you will run into an issue with floating point rounding error. If you use matrix multiplication with integers, the best you can do is THETA(log n) multiplications.

If you restrict your Fibonacci numbers in the range representable by 64-bit integers, you cannot even compute the 100th Fibonacci number without overflow. You might just precompute and use a look up table.
2019-02-10 13:41:58
Overflow個point






















因為下一題就係問你咁寫有咩問題
吹水台自選台熱 門最 新手機台時事台政事台World體育台娛樂台動漫台Apps台遊戲台影視台講故台健康台感情台家庭台潮流台美容台上班台財經台房屋台飲食台旅遊台學術台校園台汽車台音樂台創意台硬件台電器台攝影台玩具台寵物台軟件台活動台電訊台直播台站務台黑 洞