What does complexity mean. Who are difficult people? O(log n) - log complexity

Encyclopedia of Plants 03.07.2020

Surely you have often come across notations like O (log n) or heard phrases like "logarithmic computational complexity" in relation to any algorithms. And if you still do not understand what this means, this article is for you.

Difficulty rating

The complexity of algorithms is usually estimated by the execution time or by the memory used. In both cases, the complexity depends on the size of the input data: an array of 100 elements will be processed faster than a similar one of 1000. At the same time, few people care about the exact time: it depends on the processor, data type, programming language, and many other parameters. Only the asymptotic complexity is important, i.e., the complexity as the size of the input tends to infinity.

Let's say some algorithm needs to execute 4n 3 + 7n conditional operations to process n input data elements. As n increases, the total running time will be significantly more affected by raising n to the cube than multiplying it by 4 or adding 7n. Then we say that the time complexity of this algorithm is O(n 3) , i.e., it depends cubically on the size of the input data.

The use of capital O (or the so-called O-notation) comes from mathematics, where it is used to compare the asymptotic behavior of functions. Formally, O(f(n)) means that the running time of the algorithm (or the amount of memory occupied) grows depending on the amount of input data no faster than some constant multiplied by f(n) .

Examples

O(n) - linear complexity

Such complexity has, for example, the algorithm for finding the largest element in an unsorted array. We will have to go through all n elements of the array to figure out which one is the maximum.

O(log n) - log complexity

The simplest example is binary search. If the array is sorted, we can check if it contains a particular value by bisecting. Let's check the middle element, if it is greater than the desired one, then we will discard the second half of the array - it is definitely not there. If less, then vice versa - we discard the initial half. And so we will continue to divide in half, as a result, we will check log n elements.

O(n 2) - quadratic complexity

Such complexity has, for example, the insertion sort algorithm. In the canonical implementation, it consists of two nested loops: one to go through the entire array, and the second to find a place for the next element in the already sorted part. Thus, the number of operations will depend on the size of the array as n * n , i.e. n 2 .

There are other difficulty ratings, but they are all based on the same principle.

It also happens that the running time of the algorithm does not depend on the size of the input data at all. Then the complexity is denoted as O(1) . For example, to determine the value of the third element of an array, you don't need to remember the elements or iterate over them a number of times. You always just need to wait for the third element in the input data stream and this will be the result, which takes the same time to calculate for any amount of data.

Similarly, evaluation is carried out from memory, when it is important. However, algorithms can use significantly more memory when increasing the size of the input data than others, but still run faster. And vice versa. This helps to choose the best ways to solve problems based on current conditions and requirements.

Difficulty, complexity, pl. no, female distraction noun to complex. The complexity of the issue. The complexity of the case. The complexity of the international situation. ❖ In total, taking into account everything, as a result, in sum, as a whole. In total, there is still work left for ... ... Explanatory Dictionary of Ushakov

complexity- COMPLEXITY, intricacy, intricacy, difficulty, obsolete. polysyllabicity, colloquialism trickiness, razg. cunning COMPLEX, puzzling, intricate, confusing, non-unilinear, difficult, difficult, intricately woven, cunning, obsolete. ... ... Dictionary-thesaurus of synonyms of Russian speech

COMPLEXITY, and, wives. 1. see complex. 2. usually pl. Difficulty complicating circumstance. There were difficulties with the design. Explanatory dictionary of Ozhegov. S.I. Ozhegov, N.Yu. Shvedova. 1949 1992 ... Explanatory dictionary of Ozhegov

complexity- 1. Composition of several parts; diversity in the composition of the constituent parts and the relationships between them. 2. Difficulty, confusion. The opposite concept is simplicity. Dictionary of practical psychologist. Moscow: AST, Harvest. S. Yu. Golovin. 1998 ... Great Psychological Encyclopedia

complexity- - Topics information protection EN difficulty ... Technical Translator's Handbook

complexity- great complexity the greatest complexity enormous complexity extreme complexity ... Dictionary of Russian Idioms

complexity- sudėtingumas statusas T sritis radioelektronika atitikmenys: angl. complexity vok. Complexity, f rus. complexity, f pranc. complexite, f... Radioelectronics terminų žodynas

complexity- 3.8 complexity property of a system or component having a design, execution or behavior that is difficult to understand or verify. Source: GOST R IEC 61513 2011: Nuclear power plants. Control systems and ... ... Dictionary-reference book of terms of normative and technical documentation

J. distraction. noun according to adj. complex Explanatory Dictionary of Ephraim. T. F. Efremova. 2000... Modern explanatory dictionary of the Russian language Efremova

Complexity, complexity, complexity, complexity, complexity, complexity, complexity, complexity, complexity, complexity, complexity, complexity (Source: “Full accentuated paradigm according to A. A. Zaliznyak”) ... Forms of words

Books

  • Complexity and complication as a sociocultural phenomenon. Issue No. 25, Opolev P.V. The paper considers the concept of 171; complexity 187; and socio-cultural prospects for complication in the modern world, the trends of changes in human dimension, transformation in the sphere ...
  • Complexity. Math modeling. Humanitarian analysis, N. V. Belotelov, Yu. I. Brodsky, Yu. N. Pavlovsky. In the book brought to the attention of the reader, one of the central problems of using mathematical and simulation modeling in the study of socio-economic systems is discussed - ...

We recommend reading

Top