Timeline for Dynamic programming with Fibonacci
Current License: CC BY-SA 3.0
17 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 23, 2014 at 6:20 | comment | added | Dai Nguyen-Van | I followed the questioner, reuse his source code. | |
Jul 23, 2014 at 5:14 | comment | added | Pharap | @DaiNguyen-Van I was hinting that the spelling was incorrect: 'febonani' as opposed to 'Fibonacci'. And recursion is a common way to implement it as it allows compilers to use tail call optimisation. | |
Jul 23, 2014 at 5:06 | comment | added | Dai Nguyen-Van | @Pharap Fibonaci sequence definition here. I think it's not too difficult to understand it. In fact, most of Fibonaci implementation using recursion so my way might be not familiar but it shows the same result with traditional way. | |
Jul 23, 2014 at 3:54 | comment | added | Pharap | @DaiNguyen-Van What's a 'febonani'? | |
Jul 23, 2014 at 2:40 | comment | added | Dai Nguyen-Van |
On my side, after using declaration as you said: List<BigInteger> memoized = new ArrayList<BigInteger>(); , time was increased to 22ms. That is reason I keep ArrayList on both sides of that declaration.
|
|
Jul 22, 2014 at 18:46 | comment | added | Vogel612 |
what I mean is: List<BigInteger> memoized = new ArrayList<BigInteger>(); ... this should keep your running time in the same level. I did not recommend using LinkedList. It is just the reason you should be programming against interfaces, and not implementations.
|
|
Jul 22, 2014 at 16:24 | comment | added | Dai Nguyen-Van |
Thanks you so much for all your comments. I saw the problem in my old implementation. I already updated with non-recursive way to keep using ArrayList . Dear @Vogel612, I tried using List as your recommendation, it didn't raise that error but took longer than ArrayList , it can be my way is not good. I will be happy if you can edit my code to make it better.
|
|
Jul 22, 2014 at 16:14 | history | edited | Dai Nguyen-Van | CC BY-SA 3.0 |
Change algorithm from recursive way to non-recursion
|
Jul 22, 2014 at 12:04 | comment | added | Vogel612 |
@DaiNguyen-Van sorry if that sounds blunt. Can you read? I told you to not import java.awt.List , but instead java.util.List . Importing the util List should fix your issue.
|
|
Jul 22, 2014 at 11:48 | comment | added | Simon Forsberg |
When using an ArrayList , you really need to be sure that the values are put on the correct indexes. I feel that you cannot be that certain about that here. Your code here returns the sequence 0 1 1 2 3 4 7 11 18 36 which is incorrect. I would definitely go with a Map<Integer, BigInteger> instead.
|
|
Jul 22, 2014 at 11:26 | comment | added | VIckyb | @Dai : i mean to say n can be 100 but your adding to arraylist the value of 100 at may 40 place suppose in that this may fail | |
Jul 22, 2014 at 11:20 | comment | added | Dai Nguyen-Van |
@VIckyb: yes, if(n <= 2) statement handled that. @Vogel612: import one of them return the same error.
|
|
Jul 22, 2014 at 8:47 | comment | added | VIckyb | IS the logic of using ArrayList is correct for 2 the fibonacci value is 1 does your logic handle this | |
Jul 22, 2014 at 8:29 | comment | added | Vogel612 |
You use the wrong import. Don't use java.awt.List , but java.util.List
|
|
Jul 22, 2014 at 8:04 | comment | added | Dai Nguyen-Van | I tried to replace but encountered this error: The type List is not generic; it cannot be parameterized with arguments | |
Jul 22, 2014 at 7:49 | comment | added | Vogel612 |
You might want to elaborate a bit on why ArrayList is better than HashMap . Additionally you should declare memoized as a List<BigInteger> . That makes swapping ArrayList for e.g. LinkedList much easier
|
|
Jul 22, 2014 at 7:36 | history | answered | Dai Nguyen-Van | CC BY-SA 3.0 |