Open In App

Difference between average case and amortized analysis

Last Updated : 15 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Average case analysis is a type of algorithm analysis that takes into account the distribution of inputs that an algorithm is likely to encounter in practice.

  • In contrast to worst-case analysis, which considers the performance of an algorithm on the input that causes it to take the longest time to execute, the average-case analysis assumes that the input data is generated randomly according to some probability distribution. It then estimates the expected running time of the algorithm over all possible inputs.
  • The average-case analysis is useful when the probability distribution of the input is known or can be estimated, and when the worst-case analysis is not a good indicator of the algorithm’s performance in practice. 
  • However, it can be more complex and time-consuming than worst-case analysis, as it requires knowledge of the input distribution and often involves more complicated mathematical calculations.

Amortized analysis is a technique used to determine the average time complexity of an algorithm over a sequence of operations, rather than just for a single operation.

  • In some cases, an individual operation of an algorithm may be very costly, but it can be shown that the overall cost of a sequence of operations is much lower than the sum of the costs of the individual operations. The amortized analysis aims to capture this phenomenon by providing an upper bound on the average cost per operation over a sequence of operations.
  • There are several methods of amortized analysis, including aggregate analysis, accounting method, and potential method. 
    • The aggregate analysis involves finding the total cost of a sequence of operations and dividing it by the number of operations. 
    • The accounting method involves assigning credits and debits to operations to ensure that the total cost of a sequence of operations is no more than the sum of the actual costs of the operations. 
    • The potential method involves assigning a “potential” value to the data structure being used by the algorithm and using this potential to account for the difference between the actual cost of an operation and its amortized cost.

Difference between average case and amortized analysis:

 

Average Case Analysis

Amortized Analysis

Input Considers probability distribution of inputs. Considers a sequence of operations.
Goal Determines the expected time complexity over all possible inputs. Determines the average time complexity of a sequence of operations.
Complexity Measure Expected running time. Average running time per operation.
Examples Sorting algorithms like QuickSort, and MergeSort Dynamic data structures like dynamic arrays, binary heaps, and hash tables.
Applicability Applicable when the probability distribution of the input is known or can be estimated. Applicable when the probability distribution of the input is known or can be estimated.
Complexity More complex and time-consuming than worst-case analysis, as it requires knowledge of the input distribution and often involves more complicated mathematical calculations. Typically less complex and more straightforward than average case analysis.
Methods The most common method is to calculate the expected running time over all possible inputs. There are three main methods: aggregate analysis, accounting method, and potential method.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads