daniel
daniel

Reputation: 143

How to calculate Recursion runtime (java)

i have this function that print numbers from Binary tree if the numbers in range [a,b]

public void print_in_range(Node root,int a, int b){ // print all num in [a,b] --> (a < b) 
    if(root == null)
        return;
        
    if(root.value >= a  && root.value <= b)
        System.out.print(root.value + ",");
    
        print_in_range(root.left, a, b);
        print_in_range(root.right, a, b); 
}
  1. What is the runtime of the function?

  2. what will be the formula of the function?

For example:

T(n) = 3T(n/4) + n --> T(n) = O(n)

Upvotes: 0

Views: 100

Answers (1)

Mohammed Faour
Mohammed Faour

Reputation: 948

u can use the master theorem to calculate the run time complexity of this particular function. you can find the theorem here Complexity of recursive algorithms

Upvotes: 1

Related Questions