Ad
  • Custom User Avatar

    I was wondering that myself, niklasb, but then I found this on Wikipedia:
    "If the input is given as a subroutine for calculating ƒ, the cycle detection problem may be trivially solved using only λ+μ function applications, simply by computing the sequence of values xi and using a data structure such as a hash table to store these values and test whether each subsequent value has already been stored. However, the space complexity of this algorithm is λ+μ, unnecessarily large. Additionally, to implement this method as a pointer algorithm would require applying the equality test to each pair of values, resulting in quadratic time overall. Thus, research in this area has concentrated on two goals: using less space than this naive algorithm, and finding pointer algorithms that use fewer equality tests."

  • Custom User Avatar

    what the heck kind of restriction is that?! How is one solution "better" than the other if it has the same asymptotic complexity, same code length and same real-world performance. That's just arbitrary.

  • Custom User Avatar

    You should tell that Hash has been disabled in the instructions. I was trying my solution and wondering why it didn't work at all!

  • Custom User Avatar

    Yep thanks I didn't manage to delete the Hash class or its methods, instead I return nil in the most useful methods . . .

  • Custom User Avatar

    Still allows doing this: my_hash = {}

  • Custom User Avatar

    Done. No more hashes.

  • Custom User Avatar

    I didn't think of doing that. I added a time but it didn't really help. Thanks for the tip !!