Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Note the sub-optimality of generatePermutations.

For the second but last level (which will be entered n! times) it is doing n iterations which gives us a (not so tight) lower bound of n * n! instead of the optimal n!.

The issue is the use of an array for visited instead of, say, a linked list where each level gets a list of only unvisited nodes.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: