What is the big-O of the function (log n)^k

Any function whose runtime has the form (log n)k is O((log n)k). This expression isn’t reducable to any other primitive function using simple transformations, and it’s fairly common to see algorithms with runtimes like O(n (log n)2). Functions with this growth rate are called polylogarithmic. By the way, typically (log n)k is written as logk n, so the above … Read more

Best way to represent a fraction in Java?

It just so happens that I wrote a BigFraction class not too long ago, for Project Euler problems. It keeps a BigInteger numerator and denominator, so it’ll never overflow. But it’ll be a tad slow for a lot of operations that you know will never overflow.. anyway, use it if you want it. I’ve been dying … Read more

Division of integers in Java

Converting the output is too late; the calculation has already taken place in integer arithmetic. You need to convert the inputs to double: Note that you don’t actually need to convert both of the inputs. So long as one of them is double, the other will be implicitly converted. But I prefer to do both, for symmetry.

Converting from Radians to Degrees

You want to calculate radians=tan(y/x) first. Then you can convert it to degrees: See the reference here for atan: On a side note, you also have to take into account what quadrant you are in to get the correct answer (since -y/x is the same number as y/-x)

How do I compute derivative using Numpy?

You have four options Finite Differences Automatic Derivatives Symbolic Differentiation Compute derivatives by hand. Finite differences require no external tools but are prone to numerical error and, if you’re in a multivariate situation, can take a while. Symbolic differentiation is ideal if your problem is simple enough. Symbolic methods are getting quite robust these days. SymPy is … Read more