Complexity | What Do You Understand By Worst Case, Best Case And Average Case?

Here we will discuss Complexity And What Do You Understand By Worst Case, Best Case, And Average Case? As complexity is defined as the unit of measurement of total space, and time occupied by a program to run in ideal conditions.

Complexity

Ways To Measure Complexity

There are some ways to measure the complexity of a program where we check how much time the program will take to execute or we can say how much memory it will be occupying for executing the program.

Ways to represent

we present the complexity in three ways worst Case, Best Case Case, And Average Case, To learn more about let’s look at the below.

Worst Case

In this way of complexity, we look at the condition where the worst thing that could happen for example we are searching for an element in an array and that element is present is found at the last time when we search.

We represent the worst Case by O(X) (Big O notation). most of the time it is directly exponential proposing to the number of loops that if there are two nested for loops then the complexity will be O(X^2).

Best Case

It is a situation when we try to search for some element in an array or any other data type and luckily we could do it on the first try only and it stores execution next time means the program run only once.

Always the Best Case is constant that is O(1)

Average Case

It is an Average Case time complexity where it takes the Average time taken to execute all the cases that we can not represent with Big O notation but we can visualize like it will be the Average of worst and best cases.

To learn more about Java Visit Java Tutorials and also visit How do I Reverse a List backward? | Python Tutorial To learn more about python.

And also visit Complexity of Algorithms in java to learn Complexity | What Do You Understand By Worst Case, Best Case, And Average Case?

Leave a Comment

%d bloggers like this: