程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Day 21 impact Blue Bridge Cup Python data structure and algorithm 01 time complexity

編輯:Python

It refers to the execution efficiency of the algorithm
The relationship between the execution time of the algorithm and the input value of the algorithm
for/while loop O(n)
Acyclic Is a constant O(1)
Common time complexity case analysis :
O(1):

def O1(num):
i=num
j=num*2
return i+j

O(log n):

def O1(num):
i=num
j=num*2
return i+j

O(n):

def OlogN(num):
i=1
while(i<num):
i=i*2
return i

O(m+n):

def OMN(num1,num2):
total=0
for i in range(num1):
total+=i
for j in range(num2):
total+=j
return total

O(nlog n):

def ONLogN(num1,num2):
total=0
j=0
for i in range(num1):
while(j<num2):
total += i+j
j=j*2
return total

O(n^2):

def ON2(num):
total=0
for i in range(num):
for j in range(num):
total += i+j
return total

O(1) < O(logN) ( Two points search ) < O(N) < O(NlogN) < O(N^2) < O(2^n) < O(n!)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved