-
[30일코딩] Recursion개발입문/JAVA 2017. 5. 6. 17:53
재귀, 귀납, 반복
Recursion
The process of defining a function or calculating a number
by the repeated application of algorithm.
Same function within the function
- 함수 안에 함수 호출
- f(f(f(x)))
- 러시아 인형처럼;
사용법
- Base Case & Recursive Case
- Same function within the function
public static int Summation(int x) {
// Base Case : At the End
if (x <= 0) {
return 0;
// additive identity property
// Recursive Case : Keep Going
} else {
return x + Summation(x-1);
}
}
public static int exponentiation(int x, int y) {
// Base Case : At the End
if (y <= 0) {
return 1;
// multiplication identity property
// Recursive Case : Keep Going
} else {
return x * exponentiation(x, y-1);
}
}
'개발입문 > JAVA' 카테고리의 다른 글
[30일코딩] Class 구조 (0) 2017.05.06 [30일코딩] Binary Numbers 2진법 (0) 2017.05.06 [30일코딩] 딕셔너리 Dictionary (0) 2017.05.06 [30일코딩] 배열 (0) 2017.05.06 [30일코딩] 반복문 (0) 2017.05.05