El pride no es unos tenis de Adidas.

De la misma manera en que Disney no es la realidad, el día del orgullo está lejos de ser una campaña publicitaria con la que grandes marcas buscan congraciarse con una “comunidad” estampando…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Time and Space Complexity

Sometimes when we saw a problem we found that there are multiple ways to solve that problem. But we choose the one which is very efficient. But now the problem comes how we can say that particular solution is efficient, so for this, we have to compare all the solutions. For Comparing any two objects we need some points like:

If we say a is greater than b: then we compare the values of a and b.

Same way in algorithm comparison we use the running time and space required for a particular solution. Whichever is efficient we say that this is the optimized solution.

Now the problem is how we calaculate the time and space required for an algorithm.

How to calculate This:

Consider writing the program of Linear Search. There we will found that we are comparing each element with key
So that means we are iterating n times. So it became O(n).

Notations:

Big O — Worst Case (Upper Bound)
Big Theta — Average Case (Tight Bound)
big Omega — Best case (Lower Bound)

Worst Case:

2. Input is the one for which the algorithm runs the slowest.

Best Case:

2. Input is the one for which the algorithm runs the fastest.

Average Case:

2. Run the algorithm many times, using many different inputs that come from some distribution that generates these inputs, compute the total running time (by adding the individual times), and divide by the number of trials.

3. Assumes that the input is random.

Examples:

Linear Search, Binary Search, Sorting Algorithms, etc.

Thanks for reading!

Add a comment

Related posts:

Working hard from home or hardly working at home?

Which category you fall into will determine and can provide a likelihood estimation of how life has been for you over this phase. While most were exuberant at the announcement of work from home for…

7 Trending Jeans For Women In 2021

Jeans and denim are an essential part of dressing and choosing the right pair is like choosing a friend. After spending a year in pyjamas getting back to jeans has become horrifying for many of us…