I'm having trouble finding the time complexity of a function. This is the function:
int Mystery(Node root){
if(root==null)
return null;
if(root.leftchild==null)
return null;
return Mystery(root.leftchild)
}
what made me get confused is that there are 2 base conditions
this is what I wrote:
t(n)=t(n/2)+2 (2 stands for the 2 if conditions)
t(n)=t(n/4)+2+2
t(n)=t(n/8)+2+2+2
t(n)=t(n/2^k)+2*k
assume n/2^k=1
so k=log(n)
t(n)=t(1)+2log(n)
so O(log(n))
Is this correct or is there something missing?