Skip to content

Commit

Permalink
[#7] 이것이 파이썬 코딩테스트다 BFS DFS - 재귀
Browse files Browse the repository at this point in the history
  • Loading branch information
hyesuuou committed Feb 10, 2022
1 parent 4a1e4a4 commit 252e540
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions PythonCodingTest/DFS-BFS/5-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 재귀함수 - 종료조건을 항상 명시해야 한다.
# 재귀함수는 컴퓨터 내부에서 스택 자료구조를 이용하여 실행된다.

# 100번째 종료됨
def recursive_function(i):
if i == 100:
return
recursive_function(i+1)
print(i)

recursive_function(20)
15 changes: 15 additions & 0 deletions PythonCodingTest/DFS-BFS/5-5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 반복을 사용하여 구현
def factorial_iterative(n):
result = 1
for i in range(1, n+1):
result *= i
return result

# 재귀를 사용하여 구현
def factorial_recursive(n):
if n<=1:
return 1
return n * factorial_recursive(n-1)

print("반복", factorial_iterative(5))
print("재귀", factorial_recursive(5))

0 comments on commit 252e540

Please sign in to comment.