Default recursion Maximum 1000
Do not modify the default recursive maximum
Often recursion is linked to the loop.
People understand loops, God understands recursion
Algorithm
recognize recursion
How does the recursive function read?
examples
Algorithm: A method of computation
Typical problems: bubble sort, quick sort, heap sort
Binary search: Find 58 of the examples below
Two-point search
defFind_2 (l,aim,start=0,end=None):ifEnd = = None:end = Len (l)-1ifEnd >=Start:mid= (End-start)//2 +StartifL[mid] >Aim:ret= Find_2 (l,aim,start,mid-1) returnretelifL[mid] <Aim:ret= Find_2 (l,aim,mid+1, end)returnretElse:returnAim,midElse : Print('no content found') Find_2 (L,58)
Calculation of factorial
What is factorial: 7*6*5*4*3*2*1
Calculation of factorial
Fibonacci sequence
Fibonacci
Level three Menu
Level three Menu
menu = { 'Beijing': { 'Haidian': { 'Five crossing': { 'Soho': {}, 'NetEase': {}, 'Google': {} }, 'Zhongguancun': { 'Iqiyi Art': {}, 'Autohome': {}, 'Youku': {}, }, 'on the ground': { 'Baidu': {}, }, }, 'changping': { 'Shahe': { 'old boy': {}, 'Beihang University': {}, }, 'Tin Tong Court': {}, 'Huilongguan': {}, }, 'Chaoyang': {}, 'Dongcheng': {}, }, 'Shanghai': { 'Minhang': { "People's square": { 'Fried Chicken Shop': {} } }, 'Zhabei': { 'Train Warfare': { 'Ctrip': {} } }, 'Pudong': {}, }, 'Shandong': {},}defmenu_3 (menu): whileTrue: forKeyinchMenu:Print(key) Choice= Input ('Choice:') ifChoice = ='Q' orChoice = ='b': returnChoiceifChoiceinchMenu andMenu[choice]: Borq=menu_3 (Menu[choice])ifBorq = ='Q':return 'Q'menu_3 (menu)
python-recursive function