Ad
  • Default User Avatar

    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.

  • Default User Avatar

    Big-O notation ignores constant factors. You should not write O(2n). It's just O(n).

  • Custom User Avatar

    No need to apologize :-)

  • Default User Avatar

    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. :(

  • Custom User Avatar

    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.

  • Default User Avatar

    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...

  • Default User Avatar

    even with tail recursion, there's still more over head especially for a problem like this? Tail recursion can also mask infinite recursion.

  • Default User Avatar

    I can say if it works in Chrome, I don't have Chrome but it works in Google Chrome and Firefox.

  • Custom User Avatar

    I'm not able to see the drawing - in Chrome?

  • Custom User Avatar

    Either way, it's still probably slower since it's building up the stack, which requires register swapping.

  • Default User Avatar

    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.

  • Default User Avatar

    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.

  • Default User Avatar

    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?

  • Default User Avatar

    You seem to be obsessed by big O notation but is it about this kata?

  • Default User Avatar

    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...