Home » Largest subset whose all elements are Fibonacci numbers

Largest subset whose all elements are Fibonacci numbers

by Online Tutorials Library

Largest subset whose all elements are Fibonacci numbers

What is Fibonacci Series

The Fibonacci numbers are the numbers in the integer sequence shown below.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..

The recurrence relation defines the sequence Fn of Fibonacci numbers in mathematical terms.

with seed values

F0 = 0 and F1 = 1.  

Largest subset whose all elements are Fibonacci numbers

Given a positive number array, the task is to find the largest subset of the array that contains elements that are Fibonacci numbers.

Examples

Iterating through all elements of a given array is a simple solution. Check each number to see if it is Fibonacci or not. If so, include it in the final result.

Program in C++

Output

2 8 5 1 13   

Time Complexity: The above code has an O(n) time complexity and an O(n) space complexity because we store each fibonacci number in a hash map.


Next Topic#

You may also like