java - Time complexity to convert a decimal to another base -


here code compute base version of decimal number. not sure of time complexity. thanks,

public static string converttobase(int num, int base) {     if (base > 36) {         throw new illegalargumentexception("the input argument should less or equal 36.");     }     final stringbuilder sb = new stringbuilder();     while (num > 0) {         final int div = num % base;         if (div > 9) {             final int sum = div + 55;             sb.append((char) sum);         } else {             sb.append(div);         }         num = num / base;     }     return sb.reverse().tostring(); } 

complexity of algorithm is

if base=36, num=35.............number of iterations 1 if base=02, num=35.............number of iterations 6

here number iterations = log of (num) base of log = base.

hence time complexity big-o(log(n))


Comments