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
1
answer
79
views
How can I save the output of heapPermutations as a list?
static void printArr(int[] a, int n)
{
for (int i = 0; i < n; i++)
Console.Write(a[i] + " ");
Console.WriteLine();
}
// ...
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
4
answers
302
views
How would one write an efficient algorithm for determining whether a set of words can be arranged into a palindrome sentence?
There's no end to the leetcode questions about finding palindrome pairs and how to determine if a given string is a palindrome, but I can't seen to find any discussion about sentence palindrome ...
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, ...
0
votes
0
answers
32
views
How priority queue and heap are similar? [duplicate]
How priority queues and heap are similar? i can not find any similarities.
I am looking for the exact answer but could not find anywhere.
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 (...
2
votes
1
answer
359
views
Heap's algorithm checking for odd and even
can someone explain why does Heap's Algorithm uses a condition statement checking for K whether it is even or odd and the swaps are different in each one?
i can't find any intuitive explanation on the ...
0
votes
1
answer
254
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 ...
-1
votes
1
answer
83
views
High volumes, long running. Life’s too short
Need help. Possibly even psychiatric help, for even attempting this!
This process promises to run for ever. Need advice on how to improve it from a performance point of view and any ideas about how to ...
0
votes
1
answer
125
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){
...
2
votes
1
answer
58
views
Value vs Reference Types in Swift using Wikipedia implementation of Heap's permutation algorithm as example
I was trying to write code for determining permutations. In Wikipedia there is psuedo code for a simple algorithm (from BR Heap). I attempted to translate the psuedo code
procedure generate(k : ...
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
39
views
Different outputs for the same function with different callbacks (Heap's Algorithm)
I'm using the Heap's Algorithm and it's working well with the callback function output console logging the outcomes. But if I change the action of the callback function output to array.push, it pushes ...
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 ...
0
votes
1
answer
2k
views
Heap's Algorithm - Non Recursive Method in Python to generate permutations
I am a newbie to programming. I am working on Heap's Algorithm, specifically non-recursive method. There is not so much explanation available on internet, to how the algorithm works. I found this ...
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 ...
2
votes
4
answers
5k
views
How can I generate all permutations of length n from a set of k elements?
For example I have this set k=5 of elements [1,2,3,4,5] and I want all permutations of length n=2.
1,2
1,3
1,4
1,5
2,1
etc etc.
Thing is I can't use STL, external math libraries etc.
What I tried is ...
-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 ...
0
votes
1
answer
406
views
Implementing Heap's Algorithm for Permutations in Python
I'm trying to implement Heap's algorithm in python, but having trouble with it repeating some of the solutions. I'm stumped with where the bug is at. Here is the implementation:
import copy
def ...
1
vote
1
answer
175
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 ...
17
votes
3
answers
20k
views
How to iterate over all unique permutations of a sequence in Rust?
Given a list of values, such as vec![0, 0, 1, 2], I would like to create an iterator that generates all of its unique permutations. That is,
[0, 0, 1, 2]
[0, 0, 2, 1]
[0, 1, 0, 2]
[0, 1, 2, 0]
[0, 2, ...
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 ...
2
votes
0
answers
106
views
Are there algorithms for generating distinct permutations for not-necessarily distinct elements?
I have been reading about algorithms like Steinhaus-Johnson-Trotter and Heap to generate permutations, including Sedgewick’s paper on the subject. But it seems these all work when all elements are ...
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 ...
0
votes
1
answer
404
views
How to return all array permutations iteratively into a two-dimensional array?
I am trying to write a program that will iterate through all possible permutations of a String array, and return a two dimensional array with all the permutations. Specifically, I am trying to use a ...
3
votes
2
answers
987
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
316
views
Heap's algorithm with permutation signature
I am making a code that can generate all the permutation of a list of elements and the signature of the permutation based on the original list.
In general the number of permutations is given by the ...
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:
...
3
votes
2
answers
452
views
Heaps algorithm in swift
I have an implementation of Heap's algorithm in Swift that I am trying to convert to NOT use inout parameters.
However I get different results for each (the second is wrong, delivering a repeated ...
0
votes
1
answer
260
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 ...
1
vote
2
answers
319
views
Permutation algorithm for n characters in x positions
e.g. A permutation algorithm for {&, *, %} to be placed in 8 positions:
&&&&&&&&&
&&&&&&&&*
&&&&&&&&...
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 ...
0
votes
0
answers
53
views
Heaps permutation algorithm done the opposite way....?
I was trying to use Heaps algorithm the opposite way by fixing elements at the beginning of array instead of last. But Im not able to get the results. Although I understood the theory part of this ...
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 ...
1
vote
1
answer
220
views
Heap alogrithm implementation in PHP produces wrong results
Below is a PHP function based on Heap algorithm for finding permutations. The function works fine in JavaScript but fails in PHP. Why ?
function generate($n,$A) {
if ($n === 1) {
var_dump(...
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 ...
2
votes
1
answer
855
views
Heap's Algorithm implementation in list of lists
I'm using Heap's algorithm to create a list-of-lists containing each permutation of said list. Each permutation will be its own list. It works properly when I print it within the algorithm, but it ...
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 ...
4
votes
1
answer
289
views
Why does duplications happen in Heap's algorithm
I want to get all permutations from elements of array. Source array is very simple:
$arr = [ 1,2,3,4 ];
I wrote the code for implement Heap's algorithm,
private function mixture( $size, array $...
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/...
5
votes
2
answers
6k
views
Heap's algorithm time complexity
can anyone tell me what exactly is the time complexity of this Heap's algorithm shown in wikipedia, https://en.wikipedia.org/wiki/Heap%27s_algorithm ?
I searched several websites and the answers are ...
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 ...
2
votes
2
answers
1k
views
Heap's Algorithm Walk-Through
So, I'm learning recursion, and I'm working on a coding challenge that requires all variations of elements in an array.
I was pointed to Heap's algorithm and this is what I've drawn up so far in ...
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
vote
1
answer
146
views
What's wrong with my Heap's Algorithm code?
My homework requires me to write a program that takes a string from the terminal (argc and argv) and print every possible permutation. I have tried to use Heap's Algorithm, but it doesn't seem to be ...
-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 ...
1
vote
1
answer
567
views
Heap's Algorithm Permutation JavaScript and Recursions' Stack?
I have an assignment to count repeated strings base on a Heap's Algorithm Permutation.The first thing I want to do is output the swapped strings, I found this code from jake's answer Can someone ...
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 ...
0
votes
1
answer
486
views
javascript non-recursive permutation algorithm performance
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 ...