mercredi 29 novembre 2017

Complexity Algorithm Analysis with if

I have the following code. What time complexity does it have?
I have tried to write a recurrence relation for it but I can't understand when will the algorithm add 1 to n or divide n by 4.

void T(int n) {
  for (i = 0; i < n; i++);

  if (n == 1 || n == 0)
    return;
  else if (n%2 == 1)
    T(n + 1);
  else if (n%2 == 0)
    T(n / 4); 
}

Aucun commentaire:

Enregistrer un commentaire