Computational complexity of base conversion

Naive base-conversion as you described takes quadratic time; you do about n bigint-by-smallint divisions, most of which take time linear in the size of the n-bit bigint. You can do base conversion in O(M(n) log(n)) time, however, by picking a power of target-base that’s roughly the square root of the to-be-converted number, doing divide-and-remainder by … Read more

Do iterative and recursive versions of an algorithm have the same time complexity?

The answer depends strongly on your implementation. For the example you gave there are several possible solutions and I would say that the naive way to implement a solution has better complexity when implemented iterative. Here are the two implementations: int iterative_fib(int n) { if (n <= 2) { return 1; } int a = … Read more

Big O of append in Golang

This all depends on the actual implementation used, but I’m basing this on the standard Go as well as gccgo. Slices Reslicing means changing an integer in a struct (a slice is a struct with three fields: length, capacity and pointer to backing memory). If the slice does not have sufficient capacity, append will need … Read more