-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci_app.py
More file actions
35 lines (27 loc) · 1.07 KB
/
Copy pathfibonacci_app.py
File metadata and controls
35 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import streamlit as st
def fibonacci_recursive(n):
"""
Calculate the nth Fibonacci number using recursion.
Args:
n (int): The position in the Fibonacci sequence (0-indexed)
Returns:
int: The nth Fibonacci number
Time Complexity: O(2^n) - Exponential
Space Complexity: O(n) - Due to recursion stack
"""
if n < 0:
raise ValueError("n must be non-negative")
if n <= 1:
return n
return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2)
# Streamlit app
st.title("Fibonacci Sequence - Recursive Implementation")
st.write("This app displays the result of the first example from fibonacci-python-guide.md")
# Display the result of fibonacci_recursive(10) as shown in the first example
st.subheader("Example Usage:")
st.code("fibonacci_recursive(10)")
result = fibonacci_recursive(10)
st.subheader("Result:")
st.success(f"fibonacci_recursive(10) = {result}")
# Display additional information
st.info("This uses the recursive implementation from the first example in the fibonacci-python-guide.md file.")