Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
91 views

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 ...
Dilna's user avatar
  • 465
0 votes
1 answer
79 views

static void printArr(int[] a, int n) { for (int i = 0; i < n; i++) Console.Write(a[i] + " "); Console.WriteLine(); } // ...
Genaro Castillo's user avatar
0 votes
0 answers
68 views

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 ...
Shaggy's user avatar
  • 804
0 votes
4 answers
302 views

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 ...
brubsby's user avatar
  • 488
0 votes
0 answers
91 views

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, ...
Jahleel Murray's user avatar
0 votes
0 answers
32 views

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.
Tayyab Hussain's user avatar
2 votes
2 answers
1k views

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 (...
aycee 's user avatar
  • 49
2 votes
1 answer
359 views

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 ...
YusufEmad04's user avatar
0 votes
1 answer
254 views

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 ...
aldin's user avatar
  • 169
-1 votes
1 answer
83 views

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 ...
Andy's user avatar
  • 1
0 votes
1 answer
125 views

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){ ...
Nayla's user avatar
  • 21
2 votes
1 answer
58 views

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 : ...
Bibbs1000's user avatar
0 votes
1 answer
106 views

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 ...
no lemon no melon's user avatar
0 votes
1 answer
39 views

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 ...
igortp's user avatar
  • 179
0 votes
1 answer
476 views

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 ...
DarkTrick's user avatar
  • 3,683
0 votes
1 answer
2k views

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 ...
Avy's user avatar
  • 13
1 vote
2 answers
2k views

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 ...
JTP709's user avatar
  • 130
2 votes
4 answers
5k views

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 ...
Wirkijowski Mikołaj's user avatar
-1 votes
2 answers
3k views

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 ...
anna's user avatar
  • 11
0 votes
1 answer
406 views

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 ...
jth_92's user avatar
  • 1,160
1 vote
1 answer
175 views

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 ...
Kartik Gautam's user avatar
17 votes
3 answers
20k views

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, ...
Christopher Rybicki's user avatar
0 votes
1 answer
106 views

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 ...
cstover's user avatar
  • 171
2 votes
0 answers
106 views

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 ...
CTMacUser's user avatar
  • 2,072
1 vote
0 answers
177 views

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 ...
Garais16's user avatar
0 votes
1 answer
404 views

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 ...
BoxerDog's user avatar
3 votes
2 answers
987 views

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 ...
totalnoob's user avatar
  • 2,781
1 vote
1 answer
316 views

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 ...
user3671704's user avatar
1 vote
1 answer
408 views

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: ...
winged hussar's user avatar
3 votes
2 answers
452 views

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 ...
stevenpcurtis's user avatar
0 votes
1 answer
260 views

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 ...
Roijjer's user avatar
  • 57
1 vote
2 answers
319 views

e.g. A permutation algorithm for {&, *, %} to be placed in 8 positions: &&&&&&&&& &&&&&&&&* &&&&&&&&...
amirali's user avatar
  • 2,004
6 votes
1 answer
3k views

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 ...
Siddharth Chabra's user avatar
0 votes
0 answers
53 views

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 ...
Rahul R's user avatar
2 votes
2 answers
4k views

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 ...
matthew gabriel's user avatar
1 vote
1 answer
220 views

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(...
swww's user avatar
  • 23
3 votes
1 answer
130 views

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 ...
Display Name's user avatar
2 votes
1 answer
855 views

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 ...
Display Name's user avatar
0 votes
1 answer
118 views

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 ...
Wadson Fourrien's user avatar
4 votes
1 answer
289 views

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 $...
Kudryavtsev Maxim's user avatar
2 votes
2 answers
413 views

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/...
Daniel Rangel's user avatar
5 votes
2 answers
6k views

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 ...
nightowl_nicky's user avatar
1 vote
4 answers
2k views

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 ...
Kiran's user avatar
  • 914
2 votes
2 answers
1k views

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 ...
Edson's user avatar
  • 285
0 votes
0 answers
218 views

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 ...
Edson's user avatar
  • 285
1 vote
1 answer
146 views

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 ...
Icy McSpicy's user avatar
-1 votes
2 answers
1k views

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 ...
ruby life questions's user avatar
1 vote
1 answer
567 views

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 ...
learningjavascriptks's user avatar
0 votes
0 answers
14 views

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 ...
Danora's user avatar
  • 355
0 votes
1 answer
486 views

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 ...
Michael Teitge's user avatar