4 ms·
You could always just write out all permutations and train a network on recognizing the sorted one ;-)
by dmichulke 8y ago
You could always just write out all permutations and train a network on recognizing the sorted one ;-)
- Sohcahtoa82 8y agoA storage requirement of O(n!) Sorting a mere 13 items of 1-byte each would require 6.2 GB of storage.
- senatorobama 8y agoGood interview question ;)
- dmichulke 8y agoWe just generate them on the fly - after all we're not stupid ;-) https://en.wikipedia.org/wiki/Permutation#Algorithms_to_generate_permutations https://en.wikipedia.org/wiki/Permutation#Algorithms_to_gene... .. and there "Generation in lexicographic order" This algorithm only requires you to hold the last permutation in memory to obtain a new (distinct) one.