Answer the question
In order to leave comments, you need to log in
Why do you need to know the efficiency \ complexity of the algorithm?
Good day, Khabrachane! Please help me answer this question. I rummaged through the entire Internet in search of an answer, but, in the end, I found only "What is it?", and I myself have been racking my brain for the whole day on this question. Please tell me why this is needed at all, why you need to know in what situations you need to know the effectiveness of the algorithm and how this knowledge can be used in code?
For understanding: I recently started working with algorithms and often come across the word "efficiency"\"complexity" on the Internet, I want to understand whether it is worth learning, given that I do not understand the meaning of this and do not see options for using knowledge about efficiency in the code.
Answer the question
In order to leave comments, you need to log in
There are two algorithms for one task:
- one iterates through all the elements once and does something, performing the given task O(N)
- the other iterates through all the elements for each element: O(N^2)
When the number of elements is N=10 , in the loop in the first case there will be 10 operations, in the second case 100 (seemingly, 10 times as many as the element ones)
But when increasing to N=1000 in the first case there are 1000 passes, in the second there are already 1,000,000! See how much the difference grows.
Even with small values of N this can be important if each operation is long/heavy and even 2-3x increase can be a problem.
All modern cryptography (https connections in the browser) and cryptocurrencies are based on algorithmic complexity. All of them work today and exist only because there are algorithms that work in one direction easily and quickly (applying an electronic digital signature) and in the opposite direction - so tight and infinitely long that the generation of a false signature itself becomes unprofitable for an attacker simply by time costs.
And speaking in simple words, the entire subset of algorithms is divided into constant O (1) - this is a search in a hash table. Logarithmic O(Log n) is a search in a tree or a sorted collection. Linear - any search in an arbitrary collection O(n). And then there are polynomial (it's always a cycle within a cycle) exponential O(exp n). This is where cryptography comes in. And combinatorial ones, the formula of which includes the factorial of N or is also approximated by O (n ^ n). The latter just create the same class of algorithms unsolvable by science for which they try to build quantum devices that work on completely different physical principles.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question