This article is a note about learning data structures.
【】
Code
#example.py#example of algorithmic time complexitydeffunc_01 (n):" "time complexity O (log (N ))" " ImportMath I=N Count=0 whileI > 1: I= Round (Math.sqrt (i))#Note: sqrt (i)!Count + = 1returnCountPrint('time complexity O (log (N)), n=2000000000000000000, loop {} times'. Format (func_01 (2000000000000000000)))deffunc_02 (n):" "time Complexity O (Log (N))" "I=N Count=0 whileI >= 1: I= I//2#Note://2!Count + = 1returnCountPrint('time Complexity O (Log (N)), n=100000000, loop {} times'. Format (func_02 (100000000)))deffunc_03 (n):" "time Complexity O ((Log (N)) ^2)" "I= 1Count=0 whileI <=n:j=N whileJ >0:j= J//2#Note://2!Count + = 1I= i * 2#Note: * 2! returnCountPrint('time Complexity O ((Log (N)) ^2), n=100000000, loop {} times'. Format (func_03 (100000000)))deffunc_04_01 (n):" "time Complexity O (Sqrt (N))" "I= s = 1Count=0 whiles <n:i= i + 1s= S +I count+ = 1returnCountPrint('time Complexity O (Sqrt (N)), n=10000, loop {} times'. Format (FUNC_04_01 (10000)))deffunc_04_02 (n):" "time Complexity O (Sqrt (N))" "I= 1Count=0 whileI * I <N:count= Count + 1I= i + 1returnCountPrint('time Complexity O (Sqrt (N)), n=10000, loop {} times'. Format (FUNC_04_02 (10000)))deffunc_05 (n):" "time Complexity O (N)" "Count=0 forIinchRange (1, N): Count+ = 1returnCountPrint('time Complexity O (N), n=100, loop {} times'. Format (func_05 (100)))deffunc_06_01 (n):" "time Complexity O (N*log (N))" "Count=0 forIinchRange (1, N): J= 1 whileJ <=n:j= J * 2#Note: * 2!Count + = 1returnCountPrint('time Complexity O (N*log (N)), n=1000, loop {} times'. Format (func_06_01 (1000)))deffunc_06_02 (n):" "time Complexity O (N*log (N))" "Count=0 forIinchRange (1, N): J= 1 whileJ <n:j= j + I#Note: + i!Count = Count + 1returnCountPrint('time Complexity O (N*log (N)), n=1000, loop {} times'. Format (func_06_02 (1000)))deffunc_06_03 (n):" "time Complexity O (N*log (N))" "Count=0 forIinchRange (1, N//3):#Note://3!j = 1 whileJ <=n:j= j + 4#NOTE: + 4!Count = Count + 1returnCountPrint('time Complexity O (N*log (N)), n=1000, loop {} times'. Format (FUNC_06_03 (1000)))deffunc_07 (n):" "time Complexity O (n (Log (N)) ^2)" "Count=0 forIinchRange (1, N): J= 1 whileJ <=n:k= 1 whileK <=N:count+ = 1k= k * 2#Note: * 2!j = J * 2#Note: * 2! returnCountPrint('time Complexity O ((N*log (N)) ^2), n=100, loop {} times'. Format (func_07 (100)))deffunc_08 (n):" "time Complexity O (n^2)" "Count=0 forIinchrange (n): forJinchrange (N): Count+ = 1returnCountPrint('time Complexity O ((n^2), n=100, loop {} times'. Format (func_08 (100)))deffunc_09 (n):" "time Complexity O (n^3)" "Count=0 forIinchrange (n): forJinchrange (n): forKinchrange (N): Count+ = 1returnCountPrint('time Complexity O ((n^3), n=50, loop {} times'. Format (func_09 (50)))
An example of the time complexity of the algorithm