# 递归算法的时间复杂度

XAMPP新闻 589浏览

[{“id”:1,”name”:”./”},{“id”:2,”name”:”./1.txt”},
{“id”:3,”name”:”./dir1/”},
{“id”:4,”name”:”./dir1/2.txt”},…]

tree = []
def getTree(pid):
return
for index in childIndexes:
if len(tree) == 0:
if index.is_directory==1 tree.append(
{‘id’:index.id,’name’:’./’+index.index_name+’/’})
getTree(index.id)
else:
tree.append(
{‘id’:index.id,’name’:’/’+index.index_name})
else:
for item in tree:
if item[‘id’] == index.id
if item.is_directory==1: tree.append({‘id’:index.id,’name’:
item[‘name’]+index.index_name+’/’})
else:
tree.append
(
{‘id’:index.id,’name’:item[‘name’]+index.index_name
}
)

tree = []
def getTree(pid,path=’./’):
return
for index in childIndexes:
if len(tree) == 0:
if index.is_directory==1 tree.append({‘id’:index.id,
‘name’:path+index.index_name+’/’})
getTree(index.id,
path+index.index_name+’/’)
else:
tree.append({‘id’:index.id,
‘name’:path+index.index_name})
else:
if item.is_directory==1: tree.append({‘id’:index.id,
‘name’:path+index.index_name+’/’})
else:
tree.append({‘id’:index.id,
‘name’:path+index.index_name})

def fibSquence(n):
if n in (1,2):
return
fibSquence(n-1)+ fibSquence(n-2)

fibMap = {1:1,2:2}
def fibSquence(n):
else:
result = fibSquence(n-1)+ fibSquence(n-2) fibMap.update({n:result})
return result

fibMap = {1:1,2:2}
def fibSquence(n):
else:
for i in range(3,n+1):
fibMap.update({i:fibMap[i-1]+fibMap[i-2]})
return fibMap[n]