Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

big o - what is complexity of my code in big-o notation

There is a code and i'm curious about the algorithmic complexity of this code in the big-o notation.

def listsum(numList):
   if len(numList) == 1:
        return numList[0]
   else:
        return numList[0] + listsum(numList[1:])
question from:https://stackoverflow.com/questions/65860962/what-is-complexity-of-my-code-in-big-o-notation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Bro - after a while considered the complexity is O ( n*(n+1)/2 ). Explanation: Recursive operations on 1D array can be visualized like building triangular numbers because those are tiangular numbers. Jarmod was right my previous answer was wrong


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...