We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Because the next step only depends on the 3 previous steps, you can use a circular buffer of lenght 3, hence the "mod 3". So even for an arbitrary big value of n, you will never get out of memory by allocating a huge array.
So, for a n = 4, the array[0] would be ignored, for a n = 5, array[0] and array[1], etc... abgcmu solution just reuses the unused positions of the array.
Recursion: Davis' Staircase
You are viewing a single comment's thread. Return to all comments →
Because the next step only depends on the 3 previous steps, you can use a circular buffer of lenght 3, hence the "mod 3". So even for an arbitrary big value of n, you will never get out of memory by allocating a huge array.
So, for a n = 4, the array[0] would be ignored, for a n = 5, array[0] and array[1], etc... abgcmu solution just reuses the unused positions of the array.
Hope that helped.