I would have a general question. Have you ever had to really calculate (for example, on paper) the complexity of the algorithm, except at school as a programmer? And if .. can you give me an example, please.
Thank you:)
If you are writing a piece of software, and you can think of several ways to implement it, often one of the decisive factors (in addition to the conceptual complexity and time for implementation) will be complex algorithmic. Thus, when your boss wants to justify your decision, you need to find out the complexity of each of them. While some may consider this form of premature optimization, I think the consensus is that choosing a design that is right for your problem is just good software development.
- , . , (O (n ^ 3)) . . , , .
, , - , O (n ^ 3), , 3 , .
, , N , , - .
, . Quicksort - O (n ^ 2) O (n * log (n)) , - O (log (n)) .. , , , .
, . -, , " X, O (N ^ 2), , ".
, .
, , , ( ) , .
! - , .
, , - , . - .
.
, , , . , , (.. ), - . .
, , , , .
, . - 10 , , . , , , . , , func (i) {return records [i];} :
func(i) { for each index in records if i==index return records[index] next }
, , , . , , , , , .
-Adam
, , , , , . , . O (N 2) O (N) O (N) O (log 2 N). SQL - - , O (N 2) O (N) ( O (1), ).
I wrote a tool to align dependencies of RPMs of a set of packages in a single chain. The obvious solution was too slow, so I dug my memory a bit to remember the algorithm O(n+m)from the graph theory class. I did a small count of envelopes to make sure that it really was O(n+m), then wrote it and put it into production :)
O(n+m)