Q:

Timecomplexity analysis of function, Big O

What time-complexity will the following code have in respect to the parameter size? Motivate.
// Process(A, N) is O(sqrt(N)). 

Function Complex(array[], size){
    if(size == 1) return 1;
    if(rand() / float(RAND_MAX) < 0.1){
        return Process(array, size*size)
             + Complex(array, size/2)
             + Process(array, size*size);
    }
}

I think it is O(N), because if Process(A, N) is O(sqrt(N)), then Process(A, N*N) should be O(N), and Complex(array, size/2) is O(log(n)) because it halves the size every time it runs. So on one run it takes O(N) + O(log(N)) + O(N) = O(N).
Please correct me and give me some hints on how I should think / proceed an assignment like this.
I appreciate all help and thanks in advance.

A:

The time complexity of the algorithm is O(N) indeed, but for a different reason.
The complexity of the function can be denoted as T(n) where:
T(n) = T(n/2)       +       2*n
        ^                   ^
      recursive          2 calls to 
      invokation        Process(arr,n*n),
                          each is O(n(

This recursion is well known to be O(n):
T(n) = T(n/2) + 2*n = 
     = T(n/4) + 2*n/2 + 2*n = 
     = T(n/8) + 2*n/4 + 2*n/2 + 2*n
     = ....
     = 2*n / (2^logN) + ... + 2*n/2 + 2*n
     < 4n
     in O(n)

Let's formally prove it, we will use mathematical induction for it:
Base: T(1) < 4 (check)
Hypothesis: For n, and for every k<n the claim T(k) < 4k  holds true.
For n:
T(n) = T(n/2) + n*2 = (*) 
     < 2*n + 2*n 
     = 4n

Conclusion: T(n) is in O(n)
(*) From the induction hypothesis

