to understand how an algorithm can perform on different sizes of input we need to analyze the algorithm in different cases. and to compute the best, average, and worst running time of an algorithm we need to consider three cases of an algorithm.

suppose we have an algorithm as shown in the given below image. and we run this algorithm on different inputs and for every input the running time for the algorithm is different. as you see in the image. so, in this case, to analyze the algorithm in particular inputs we consider three cases.

let's say if we are searching an element in an array using a searching algorithm then if an element is found at the last index then it's a worst-case for the algorithm. so generally we consider an input for which the algorithm takes the longest time to execute.
Note: The worst case is very informative and is usually done because an algorithm can't execute in a time that is greater than the worst case.
for example, if we search an element into an array and we found that array at the first element of an array. then it's a best-case for an algorithm.
so generally to computer best case of an algorithm, we consider an input for which the algorithm takes the shortest time.
Note: this case is not very informative because it doesn't show the real execution time of an algorithm.
let's say we search for an element in an array and the element is found in the middle of the array. then it's an average case for the algorithm.
so usually to computer average case of an algorithm, we consider all possible inputs a computer average running time.
Note: generally it's very difficult to compute the average case. because the input size is very.
Worst average and Best-case analysis of algorithm

suppose we have an algorithm as shown in the given below image. and we run this algorithm on different inputs and for every input the running time for the algorithm is different. as you see in the image. so, in this case, to analyze the algorithm in particular inputs we consider three cases.

Three cases of algorithm
- Worst case
- Best case
- Average case
Worst-case analysis of algorithm
it's is a case when an algorithm will take a maximum running time for input size n to execute.let's say if we are searching an element in an array using a searching algorithm then if an element is found at the last index then it's a worst-case for the algorithm. so generally we consider an input for which the algorithm takes the longest time to execute.
Note: The worst case is very informative and is usually done because an algorithm can't execute in a time that is greater than the worst case.
Best-case analysis of algorithm
it's a case when the algorithm will take the minimum running time for an input size.for example, if we search an element into an array and we found that array at the first element of an array. then it's a best-case for an algorithm.
so generally to computer best case of an algorithm, we consider an input for which the algorithm takes the shortest time.
Note: this case is not very informative because it doesn't show the real execution time of an algorithm.
Average case analysis of algorithm
it's a case when an algorithm takes an average running time for an input size n to execute.let's say we search for an element in an array and the element is found in the middle of the array. then it's an average case for the algorithm.
so usually to computer average case of an algorithm, we consider all possible inputs a computer average running time.
Note: generally it's very difficult to compute the average case. because the input size is very.
Also, read other tutorials as well
- What are Data Structures and algorithms
- Algorithm design and analysis
- Classification of algorithms
- How to calculate the running time of an algorithm
- Big o notation
- Big o notation examples
- Linked List in Data Structures
- Traversing in Linked list
- Operations on the linked list
- Insertion in the linked list
- Deletion in a linked list
- Reversing a linked list
- Sorting a linked list
- Find and remove the loop in the linked list
- Doubly linked list
- Insertion in the doubly linked list
- Deletion in the doubly linked list
- Reversing a doubly linked list
- Circular linked list
- Insertion in the circular linked list
- Deletion in the circular linked list
- Merge two linked list
- Header linked list
- Sorted linked list
- Stack in data structures
- Queue in data structures
- Circular queue
- Dequeue in the data structure
- Priority queue
- Polish notation
- Tree in the data structure
- Binary tree
- Array representation of the binary tree
- linked representation of a binary tree
- Traversing in the binary tree
- Inorder traversal in the binary tree
- Preorder traversal in the binary tree
- Postorder traversal in the binary tree
- Level order traversal in the binary tree
- Binary search tree
- Insertion in the binary search tree
- Deletion in the binary search tree
- Heap in data structures
0 Comments