Answer the question
In order to leave comments, you need to log in
How to calculate the complexity of an algorithm?
For example, the program analyzes the text and extracts 5 parameters from it, they are added to an array. At the next stage, the list of such arrays is processed, and when processing each one, it is required to find the maximum element, i.e. loop through the array first.
Let's say when creating an array of 5 elements, you can add if and add a value to the beginning or end of the array, so we will spend a little time here, but in the array list they will already be sorted and the maximum element will always be the first element of the array.
In this case, is it possible to mathematically calculate whether the variant will work faster with a pre-sorted array or not, and how to do it? (assume that the execution conditions and the data are exactly the same)
Answer the question
In order to leave comments, you need to log in
Suppose when creating an array of 5 elements, you can add if and add a value to the beginning or end of the array
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question