Predict the average algorithm performance and growth order using summation

I need to predict the average performance of an algorithm relative to the size of its inputs using summation / sigma notation in order to arrive at a final answer. Many resources use summation to predict the worst case, and I could not find someone explaining how to predict the average case, so phased responses are appreciated.

The algorithm contains a nested for loop with the main operation inside the innermost loop:

[code changed]

EDIT: Performs a basic operation, which will always be performed in the second cycle if the second cycle of the cycle is entered and does not have break or return statements. HOWEVER: at the end of the first for loop there is a return statement, which depends on the value obtained in the basic operation, so the contents of the array affect how long the main operation will be performed for each algorithm run.

The array passed to the algorithm has randomly generated content

I think the predicted average case efficiency is (n ^ 2) / 2, making n ^ 2 growth orders / large Theta n ^ 2, but I donโ€™t know how to theoretically prove this using summation. The answers are much appreciated!

+4
1

TL; DR: ฮ˜(nยฒ), " " ฮ˜(1), return, break goto.

: - .

, T(A, n) - , A n. ,

T(A, n) = 1  +                // int k = ceil(size/2.0);
    n * 2 + 1 +               // for (int i = 0; i < size; i++){
    n * (n * 2 + 1) +         // for(int j = 0; j < size; j++){
    n * n * X +               // //Basic operation 
    1                         // return (some int);

X - " ". , T(A, n) A. , , ( T(A, n) A n), :

T(n) = T(A, n) = 3 + n * 2 + n * n * (2 + X)

, X = ฮ˜(1), ฮ˜(nยฒ).

: X = ฮ˜(f(n)), T(n) = ฮ˜(f(n)nยฒ). , X - ฮ˜(log n), T(n) = ฮ˜(nยฒ log n)

+1

Source: https://habr.com/ru/post/1673862/


All Articles