Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Slower for what task? It is unlikely that this will be the bottleneck in your code, and stack operations are incredibly fast. They don't even incur garbage collection penalties. Regardless, such talk is certainly premature optimization. Pick a context that the code will run and then optimize for that. If no context is given, this is solution is using best practices.
Big-O notation ignores constant factors. You should not write O(2n). It's just O(n).
No need to apologize :-)
Vernon, it wasn't a criticism, just was curious as to why you chose to do it that way. My apologies if it came out as insulting. :(
Thank you very much for the information. I'm new to Java and am still learning. You are correct I'm really not sure why I did this but now after reading your comment I can see how stupid it was. Thanks once again.
Why are you doing it this way? You know under the covers that ArrayList essentially has to re copy when it allocates more space when the underlying array runs out of space right? Which is O(n) + NLog(n);
Then additionally you're going to call toArray, which is going to do another scan of the full size, so your time complexity will be O(2n) + n(log(n)) and your space complexity will be O(2n) one for the arraylist and one for the array...
even with tail recursion, there's still more over head especially for a problem like this? Tail recursion can also mask infinite recursion.
I can say if it works in Chrome, I don't have Chrome but it works in Google Chrome and Firefox.
I'm not able to see the drawing - in Chrome?
Either way, it's still probably slower since it's building up the stack, which requires register swapping.
I still think there's value in what this exercise really gets at, most algorithms today are simply math. How you write that formula in your code is up to you, but this is a math problem, not particularly a coding exercise.
Math, write out the a few cases, do you notice a pattern? Then your code should try and force the other player into the position you don't want. The code that's running this definitely is just taking two instances of your class(add some System.out.println's) very easy to detect.
big O notation is important for an algorithm, most of these problems aren't language specific, and while yes one could use language proprietary libraries which have great algorithms already, what's the point if you don't understand why they are so great and under what cases?
Why else are you doing any of these?
You seem to be obsessed by big O notation but is it about this kata?
Part of the value of not seeing all the unit tests is forcing your mind to consider other corner cases or vulnerabilities in your code.
If you really can't figure it out and are in a time crunch, add for loops to show you the function inputs, and then use that information to update your test.
Loading more items...