65 questions
0
votes
1
answer
91
views
Computing permutations with the Heap Algorithm
I am using the following the Heap Algorithm for computing permutation of words in elisp, but the permutations are not correct.
The problem could be associated with the way I use the two calls to ...
0
votes
0
answers
68
views
Heap based permutation extremely slow for larger numbers
We are using Heap algorithm for generating permutations of an array a. . The generated permutations are passed to the printArr function,
which calculates the correlation coefficient between two arrays ...
0
votes
0
answers
91
views
Trying to understand this non-recursive Heap's Permutation Algorithm
Right now I'm trying to understand why a certain non-recursive implementation of the Heap's Permutation Algorithm works. I implemented some code of this particular version of the algorithm in python, ...
2
votes
2
answers
1k
views
Generate Permutations using Heap's Algorithm
I am trying to generate all permutations for an array using the Heap's algorithm that I found in wikipedia.
This is what I tried so far:
n <- 3
A <- c(1, 2, 3)
perm <- function(n, A) {
if (...
0
votes
1
answer
252
views
Problem with Heap's algorithm: not all permutations are generated
I wanted to use the recursive version of Heap's algorithm in order to get all permutations of a sequence of natural numbers from 1 to k inclusive, but ran into certain difficulties.
For k = 3, the ...
0
votes
1
answer
124
views
why is this heap algorithm for permutation not working;
i'm preparing for an interview and was trying heap's algorithm for permutation with javascript. so the code works fine when i try to print to console.
function per(a, size){
if(size === 1){
...
0
votes
1
answer
106
views
Heap’s algorithm wiki picture vs algorithm
I’m trying to understand Heap’s algorithm from the Wikipedia page and I’m trying to compare the picture with the algorithm and I can’t seem to figure it out
this picture is from the wikipedia page
...
0
votes
1
answer
476
views
Heap's algorithm in Javascript a.k.a. all permutations
Goal:
I want to execute a specific function for every permutation of an array. I don't need to save intermediate permutations.
Paraphrase:
I'm searching for a Javascript implementation of Heap's ...
1
vote
2
answers
2k
views
Solving a Permutations problem with Heap's Algorithm in Javascript
I'm working through some "Kata's" on CodeWars.com, and am stuck on the Permutations problem.
Here is the problem: n this kata you have to create all permutations
of an input string and ...
-1
votes
2
answers
3k
views
Permutations without repetition without using itertools
I need to get all the permutations of an iterable of length n in a brute force algorithm. I dont want to use itertools or any other external packages.
I figured I could use Heap's algorithm but my ...
1
vote
1
answer
174
views
Error generating permutations using Heap's Algorithm
Objective of my code: Trying to create an ArrayList of Arrays containing all permutations of passed array 'p'.
Approach: Using Heap's algorithm, trying to generate all permutations, each permuatation ...
0
votes
1
answer
106
views
What Java List-related subtlety is causing my Heap's Algorithm implementation to fail?
I am attempting to implement "Heap's Algorithm" (wiki) in Java, which constructs all permutations of a given set. (I am aware that this isn't technically Heap's algorithm because of subtleties pointed ...
1
vote
0
answers
177
views
Time complexity of Heap's Algorithm [duplicate]
I'm studying time complexity of recursive algorithms and I want to know the complexity of the Heap's algorithm that generate all possible permutations of n objects.
procedure generate(k : integer, A ...
3
votes
2
answers
986
views
heap's algorithm - JavaScript
I have an alright understanding of how Heap's Algorithm works, but I can't figure out how to add each unique permutation into an array and return it based on the recursive nature of the algo.
why is ...
1
vote
1
answer
408
views
Heap's Algorithm producing the same permutation twice
I am currently implementing Heaps's Algorithm in Python, but my current solution is returning some of the permutations twice.
def generate(startingIndex, alist):
if startingIndex == 1:
...
0
votes
1
answer
259
views
Heap's algorithm to return array instead of printing
I am trying to get this heaps algorithm to return an array of permutations instead of printing as below. I know it could be done by declaring an array outside of the function and pushing to it but, I ...
6
votes
1
answer
3k
views
Generating k permutations from n in C
I basically need the equivalent result of the following Python itertools command in C:
a = itertools.permutations(range(4),2))
Currently my process involves first "choosing" 5 elements from ...
2
votes
2
answers
4k
views
Creating an array of all unique 4 digit numbers that can be made from the numbers 1-9 in JavaScript
I was set the task to create an array of all permutations/ 4 digit numbers of a given array of numbers: [1,2,3,4,5,6,7,8,9]. There can be no repeats of digits as each value must be unique. Below is my ...
3
votes
1
answer
130
views
Creating arrays for permutations within a subsection of a list
So I have a list:
a 25
b 18
c 18
d 18
e 14
f 14
g 12
... and so on
For each number that matches, I have to get every permutation of the identifier. The lists I would need from my example would be as ...
0
votes
1
answer
118
views
Why is my permutation algorithm giving me the same result for all permutations?
I'm stuck with some heap's permutation algorithm. I wrote some JavaScript code to recursively find every possible permutation of a value: either an array or a string. My code seems to work perfectly ...
2
votes
2
answers
413
views
Golang range through channel with odd behaviour when inplementing Heap's permutation algorithm
I was trying to implement Heap's Algorithm in go using channels. The code below is working fine when just printing the slices on the screen, but when using channels to delivery the arrays to a for/...
1
vote
4
answers
2k
views
Number of arrangements with no consecutive letter the same
This question is related to my question here. I am trying to get the following count programmatically to verify whether my mathematics is right.
How many arrangements of the letters in the word ...
0
votes
0
answers
218
views
How to read Heap's algorithm?
I'm wanting to generate all possible permutations of the letters A - G (seven) and Heap's algorithm allegedly makes this possible.
However, when I look at the pseudo code from the Wikipedia page I ...
-1
votes
2
answers
1k
views
Javascript Heap's algorithm (non-recursive)
I have implemented Heap's non-recursive algorithm in JavaScript.
When checking permutations with console.log(arr) everything works as expected.
But when I try to push each permutation to a result ...
0
votes
0
answers
14
views
Can't return the correct value from a recursive permutation function [duplicate]
I am trying to modify this blogger's version of Heap's Algorithm.
My issue is that this function prints out every permutation just fine, however if I try to add these permutations to an array which I ...