GeeksforGeeks » C/C++ Programming Questions

fibonacci series element

(3 posts)
  1. vasu
    guest
    Posted 8 months ago #

    provide a program which will print nth element in fibonacci series. conditions are
    1) O(1) time complexity
    2) try to keep the memory consumption minimum
    3) n is between 1000 to 10000. ( check for integer overflow)

  2. kartik
    Moderator
    Posted 8 months ago #

    One simple way is to preload an array of size 9000. Load all Fibonacci number in the array so that the task to get nth Fibonacci number becomes O(1).

  3. vasu
    guest
    Posted 8 months ago #

    when i got the question, thought same :) but then point 3 (integer overflow) becomes a problem, we need to keep them as an array of characters i.e. strings. so effectively it becomes, store a large number of strings efficiently, where the permissible characters are '0' to '9'. Hence trie is my opinion.


Reply

You must log in to post.

RSS feed for this topic