# Operation Counts Method in Algorithm

There are different methods to estimate the cost of some algorithm. One of them by using the operation count. We can estimate the time complexity of an algorithm by choosing one of different operations. These are like add, subtract etc. We have to check how many of these operations are done. The success of this method depends on our ability to identify the operations that contribute most of the time complexity.

Suppose we have an array, of size n [0 to n - 1]. Our algorithm will find the index of largest element. We can estimate the cost by counting number of comparison operation is performed between each pair of elements of the array. We have to remember that, we will choose only one operation. In this algorithm there are few more operations like increment of iteration variable i, or assign values for index etc. But they are not considered in this case.

## Algorithm

getMax(arr, n):
index := 0
max := arr
for i in range 1 to n - 1, do
if arr[i] > max, then
max := arr[i]
index := i
end if
done
return index

We have to choose those operations that are performed maximum amount of time to estimate the cost. Suppose we have one bubble sort algorithm, and we count the swap operation. Then we have to keep in mind that when it will be maximum. That will give us maximum result during analysis.

Updated on: 10-Aug-2020

2K+ Views 