Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 코테
- Binary Search
- geometry
- array
- 구현
- dynamic programming
- Number Theory
- database
- Data Structure
- Binary Tree
- Tree
- Counting
- SQL
- Math
- string
- Stack
- Class
- java
- greedy
- 코딩테스트
- hash table
- simulation
- bit manipulation
- 파이썬
- 자바
- two pointers
- Matrix
- Method
- sorting
- implement
Archives
- Today
- Total
코린이의 소소한 공부노트
n-th Fibonacci Term (Recursive) 본문
1. Problem
- 피보나치 수열에서 n번째 수를 재귀함수를 이용해 찾아보자
2. Input
1) 음이 아닌 정수 n
3. Output
1) n번째 피보나치 수
4. PseudoCode
int fib(int n){
if(n<=1)
return n;
else
return fib(n-1) + fib(n-2);
}
5. Example
class Test {
public static void main(String[] args){
int a = 7;
System.out.println(a + "번째 피보나치 수: " + fib(a)); // 7번째 피보나치 수: 13
}
// 피보나치 수열(0번째~10번째)
// 0 1 1 2 3 5 8 13 21 34 55
static int fib(int n) {
return n<=1 ? n : fib(n-1)+fib(n-2);
}
}
- T(n) > 2^(n/2)
'Back-End > Algorithm' 카테고리의 다른 글
Divide and Conquer (0) | 2023.02.23 |
---|---|
n-th Fibonacci Term (Iterative) (0) | 2023.02.22 |
Binary Search (iterative) (0) | 2023.02.22 |
Matrix Multiplication (0) | 2023.02.22 |
Exchange Sort (0) | 2023.02.22 |