0

if (tl;dr) {

goto https://jsfiddle.net/y5v0ur4p/60/

Any ideas on how to run this permutation-pattern faster?

} else {

I was wondering if it was possible to write a non-recursive permutation function in javascript that could keep up with the performance of recursive ones (e.g. Heap's algorithm). After a couple of weeks I had an idea which worked out pretty well so far. Here's the explanation https://jsfiddle.net/u68wyvzk/6/

In case the explanation left something unclear, just ask :) }

2

1 Answer 1

0

It is always possible to eliminate recursion by manually implementing a stack that would otherwise be implicitly handled by the JavaScript engine. Making the stack explicit allows for some optimizations (as we don't need to store the whole call stack and can eliminate function calls from within inner loops) and is often faster even though the computational complexity remains the same.

See https://stackoverflow.com/a/37580979/1647737 for a performant non-recursive implementation of Heap's algorithm.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.