Welcome to BigData School that can get you hired on Small startups or big Product based companies.Are you tired of 30-40 hours of theoritical bigdata courses in the market. Welcome to 240+ hours of Bigdata training. Just subscribe to our popup to get access to our 80+hours of course absolutely free.Try them out and you can join our further course once you are happy with our Demos.

Find Nth Fibonacci Number

Big Data    On Thursday 22nd of June 2017 12:10:06 PM By Suraz Ghimire
What is 11th fibonacci number?

//0 1 1 2 3 5 8 13 21 34 55
If we assume the above series, then 11th number is 55. considering fibonacci series starts with 0.

Given a number 11, You are required to find out the fibonacci sum which is 55 in this case.

Time complexity:T(n) = T(n-1) + T(n-2) 
Space complexity: O(n) if you consider the size occupied by stack, O(1) otherwise

package sorting.searching

object FibonacciSeriesUsingRecursion {
//0 1 1 2 3 5 8 13 21 34 55
def fibonacci(num: Int):Int={
if(num<=1)
return num
else return fibonacci(num-1)+fibonacci(num-2)

}

def main(args: Array[String]): Unit = {
val num=11
println(fibonacci(num-1))
}
}
 

output: 55

About Author

Suraz Ghimire