That is, we essentially count the number of steps involved in executing the algorithm. An intuitive explanation of complexity analysis is the following.We caution you that our explanation is clearly an oversimplification, but it suffices for our purposes.
Complexity AnalysisGiven a certain input size, assuming that to process a single element takes one unit of time, how many units of time are involved in processing n elements of input?
Complexity AnalysisNow consider the three presented comparison-based sorting algorithms. For all, the outer loop has n steps, and for the inner loop the size of the list shrinks by one with each pass. So the first time it takes n steps, the next time n – 1, the next time n – 2, and so on. Thus, the number of steps is: n + (n – 1) + (n – 2) + ... + 3 + 2 = 2 + 3 + ... + (n – 2) + (n – 1) + n
SearchingSearching a list of names or numbers is another very common computer science task. There are many search algorithms, but the key in developing a search algorithm is to determine