Time complexity of the simple java code?

Well this particular code deterministically runs in O(1).

Well this particular code deterministically runs in O(1). However, in more general terms for arbitrary variables, multiply() will run in O(nlog n) where n is the number of bits. Pow() method will run in O(log b) for small a and b.

This is achieved by exponentiation by squaring. For larger values, the number of bits gets large (linearly) and so the multiplication takes more time. I'll leave it up to you to figure out the exact analysis.

I'm not 100% about the details about modPow(), but I suspect it runs similarly to pow() except with the extra mod at each step in the exponentiation by squaring. So it'll still be O(log b) multiplications with the added benefit that the number of bits is bounded by log m where m is the mod.

– DarthVader Dec 6 at 17:36 It will run the same amount of time, each time it is run. – Peter Lawrey Dec 6 at 17:37 No that looks serious. The reasons for it are a little over my head, but some code that runs in O(1) would still in in O(1) but it may call code that runs in a different time complexity.

– Freiheit Dec 6 at 17:38 @tskuzzy,And what about modPow method? – pedja Dec 6 at 17:44 @pedja perhaps try it yourself? – Woot4Moo Dec 6 at 18:06.

Tskuzzy is correct. But maybe reading between the lines a bit, and assuming this is a homework question, they probably want you to realize that there are several operations happening in this method with varying complexities. And then they probably want you to realize that the complexity of the overall method is the same as whatever the most complex operation is that happens in the method.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions