데이터 구조 및 분석 ch_4_1 Recursions
Jul 25, 2021
»
writing
KAIST 산업및시스템공학과 문일철_ 데이터 구조 및 분석 수업을 참고하여 작성하였습니다
ch_4_1 Recursions
Recursions
1.Recursions (재귀호출)
- Repating problem
- Divide and conquer
- Recursion function call
- Recursion escape
- Recursion depth
2. Repeating Problems and Divide Conquer
- Departments consist of the company
- Departmenst within departments
3. More examples ...
- Factorial (팩토리얼)
- Great common divisor (최대 공약수)
* commonality
반복, parameters 감소
4. Recursion
: A programming method to handle the repeating items in a self-similar way
def Fibonacci(n) :
if n ==0:
return 0
if n ==1:
return 1
intRet = Fibonacci(n-1) + Fibonacci(n-2)
return intRet
for itr in range(0,10) :
print(Fibonacci(itr))
# 0
# 1
# 1
# 2
# 3
# 5
# 8
# 13
# 21
# 34
5. Recursions and Stackframe
- Recursion of functions
- Increase the items in the stackframe
: Stackframe is a stack (function call history)
: Push (function is invoked)
: Pop (function hit return or ends)
- Local variables and function call parameters
- R.A : Return Address