What is the complexity of a program with only one loop, is log n? can someone give me some ideas on evaluating code complexity?
Well, it really depends on what happens in this cycle.
This cycle is linear time, i.e. O (n):
int sum = 0; foreach( int i in SomeCollection ) { sum += i; }
However, consider a loop that searches for a substring during each iteration. Now you need to consider the complexity of the string search algorithm. Your question cannot be answered because it is worth it. You will need to provide a sample code if you want a meaningful answer.
There is a field of research that is trying to pinpoint this.
.
, , p = 2, , , .
, O (1), , , , - .
Big-O, : " "?
, , , , .
:
For (i = 0 ; i < n ; i++ ) { //Do stuff }
For (i = n ; i > 0 ; i= i/2 ) { //Do stuff }
... .
void Mess (int n) { for (i = 0 ; i < n ; i++) { //Do stuff Mess(n-1); } }
, , , ... n n-1. . n == 1, 1 . n == 2, ., , , : , , n!
, .
, , , , ... , , . , n times O(n^2) , strlen, memcpy ..
n
O(n^2)
strlen
memcpy
, , ( ) , (, Perl), O(2^n)!! .
O(2^n)
Big-O, , n times , , n - .
. , .. O (1), O (1 * n) = O (n).
, , m, O (n * m) ..
m
, "trend-prof" (https://pdfs.semanticscholar.org/8616/7f320e230641299754e0fbd860c44f5895f0.pdf)
R- GuessCompx Github.
Source: https://habr.com/ru/post/1788554/More articles:IF when starting MySQL - mysqlPdf Generation with Rails 3 - ruby-on-railsHow to sort callback chain - pythonOrder when executing specflow functions - nunitC # properties as array notation - arraysInvalid URI with Chinese characters (Java) - javaOracle: a query that considers occurrences of all non-alphanumeric characters in a string - sql[[: Command not found - bashChange the selected tab UITabBar - iphoneText format on the Android market - androidAll Articles