# Analysis of algorithm

we have completed our set of rules inside the previous phase. but one component we’ve got now not done yet is the analysis of our algorithm. A legitimate question inside the contemporary situation can be, why do we really want to have an analysis of our algorithm? though we have written the implementation, we are not positive about how many resources our written code will utilize. when we are saying resource, we suggest each time and storage aid utilized by the strolling application. We write algorithms to work with any duration of the input. so that it will apprehend how our set of rules behaves while the input grows large and how many sources have been applied, we normally degree the performance of an algorithm by means of referring to the enter period to the wide variety of steps (time complexity) or storage (area complexity). it’s miles very crucial to do the evaluation of algorithms on the way to find the maximum green algorithm to clear up the problem.

we can do set of rules analysis in two extraordinary tiers. One is finished earlier than implementation and one after the implementation. The evaluation we do before implementation is also called theoretical analysis and we expect that different elements consisting of processing strength and spaces are going to be constant. The after implementation evaluation is called empirical evaluation of an set of rules that can vary from platform to platform or from language to language. In empirical analysis, we will get stable information from the device regarding time and area usage.

For our set of rules to place the books and locating the books from purchased objects, we are able to perform a similar evaluation. at this time, we are able to be extra worried about the time complexity in preference to the distance complexity. we will explore space complexity in coming chapters.

## Calculating the complexity

There are two types of complexity we measure in algorithmic analysis:

- Time complexity: Time complexity is measured by way of the number of key operations within the algorithm. In other words, time complexity quantifies the quantity of time taken by an set of rules from start to complete.
- area complexity: space complexity defines the amount of space (in reminiscence) required by way of the algorithm in its existence cycle. It depends on the choice of facts systems and platforms.

Now allow us to focus on our applied set of rules and discover approximately the operations we’re doing for the set of rules. In our placeAllBooks feature, we are searching for each of our ordered books. So if we’ve 10 books, we’re doing the hunt 10 times. If the variety is 1000, we’re doing the hunt 1000 instances. So definitely, we are able to say if there’s n quantity of books, we’re going to seek it n number of times. In algorithm analysis, enter wide variety is often represented with the aid of n.

For each object in our ordered books, we’re doing a seek the use of the findABook function. within the characteristic, we are once more searching through each of the acquired books with a call we received from the placeAllBooks feature. Now if we are lucky sufficient, we will discover the name of the e-book at the beginning of the listing of received books. if so, we do now not need to seek the last items. but what if we’re very unfortunate and the e-book we’re trying to find is on the stop of the list? We then should seek each of the books and, on the give up, we discover it. If the number of obtained books is likewise n, then we need to run the evaluation n times.

If we expect that other operations are constant, the simplest variable ought to be the input size. we can then define a boundary or mathematical equation to outline the situation to calculate its runtime performance. We name it asymptotical evaluation. Asymptotical evaluation is input certain this means that if there is no enter, different factors are constant. We use asymptotical evaluation to find out the great case, worst case, and average case state of affairs of algorithms:

- fine case: first-class case suggests the minimum time required to execute the program. For our example algorithm, the pleasant case can be that, for each e-book, we’re most effective searching the primary item. So, we end up searching for a completely little quantity of time. We use Ω notation (Sigma notation) to suggest the exceptional case situation.
- average case: It indicates the average time required to execute a software. For our algorithm the common case can be finding the books around the middle of the list maximum of the time, or half of the time they may be at the start of the listing and the ultimate half of are at the stop of the list.
- Worst case: It indicates the maximum going for walks time for a application. The worst case example could be locating the books on the quit of the list all of the time. We use the O (large oh) notation to describe the worst case situation. For each e-book looking in our set of rules, it could take O(n) walking time. any further, we are able to use this notation to explicit the complexity of our set of rules.