Questions tagged [circular-permutations]

A cyclic permutation (or circular permutation) is a permutation built on a set of elements in cyclic order.

A cyclic permutation (or circular permutation) is a permutation built on a set of elements in cyclic order.

Wikipedia: http://en.wikipedia.org/wiki/Cyclic_permutation

29 questions
11
votes
2 answers

Using circular permutations to reduce Traveling Salesman complexity

I'm trying out a bunch of different algorithms for finding near-optimal solutions to the Traveling Salesman Problem, and one of the methods is the brute force approach - checking every possible path between n cities, and simply returning the best…
RedShift
  • 275
  • 1
  • 9
3
votes
1 answer

R: list all directionless circular permutations/arrangements (i.e. where clockwise/anti-clockwise are the same)

How do I list all the circular permutations in R where direction does not matter? I have a vector 1:4 for illustration (however, I would like a general solution). I use gtools::permutations(n = 4, r = 4) which gives me a listing of all possible…
user3236841
  • 1,088
  • 1
  • 15
  • 39
2
votes
5 answers

Inserting all elements of second list while maintaining the order of the elements in the first list in Python

I have two lists, let's say lst1 = [4, 6, 11, 0, 1, 2, 5] and lst2 = [10, 3, 8]. I would like to list all permutations of inserting lst2 into lst1 such that the order of lst1 is maintained (order of lst2 need not be maintained). All elements in both…
2
votes
5 answers

Python Algorithms: Necklace Generation / Circular Permutations

I am struggling with generating circular permutations, or solving the "Necklace Problem" with Python. I am basically looking to generate all circular permutations of a list as efficiently as possible. Basically, assume we have a list [1,2,3,4], I…
Joe
  • 31
  • 1
  • 3
2
votes
2 answers

Finding all permutations of numbers plucked from an array which sum to 16

I would like to find all the permutations of plucking 3, 4 or 5 numbers from [2,3,4,5,6,7,8], repeats allowed, such that their sum is 16. So [8,5,3], [8,3,5] and [4,3,3,3,3] are valid permutations. Also circular permutations should be removed so…
thenapking
  • 135
  • 14
2
votes
4 answers

Circular permutation in scheme

Hello I try to make circular permutations in Scheme (Dr. Racket) using recursion. For example, if we have (1 2 3) a circular permutation gives ((1 2 3) (2 3 1) (3 1 2)). I wrote a piece of code but I have a problem to make the shift. My…
Gaulthier
  • 320
  • 7
  • 16
2
votes
4 answers

shifting a sequence of numbers in C?

I have a question about some trying to wrap around a sequence of numbers that I'm trying to shift in the C programming language. The first value that is found in the sequence of numbers I calculate via a loop gets thrown out in the end. Here is what…
1
vote
1 answer

Circular permutation in C

Given a array x with n integer components, write functions that allow performing the following operation: Carry out the circular permutation of the given array I tried to do without poiters for the code, as it ends up with only arrays I think the…
1
vote
1 answer

Is it possible to compute the sign of a permutation in linear time?

I was just wondering if there's a way to compute the sign of a permutation within linear (or at least better than n^2?) time For example, let's say I have an array of n numbers and I permute two elements within this array which would flip the sign…
AlphaBetaGamma96
  • 567
  • 3
  • 6
  • 21
1
vote
2 answers

Find all cyclic permutations of a string in O(n)

Given the problem: Find all cyclic permutations of a string For example: given a string: "abcd" All the cyclic permutations of a string would be: "abcd", "dabc", "cdab", "bcda" Here's what I have tried out: for(int i = 0; i < str.size(); i++){ …
UTL
  • 65
  • 7
1
vote
1 answer

How to generate random string type primary key, which can auto increase its length?

If my table needs to use string type as its primary key, the length of which is increasable and as short as possible, and when it is available, it should be random in some sense, how can I make that? For example: given 26 letters, and the result…
1
vote
1 answer

How can I do itertools.product-controlled repetition of any character?

This is code with 8 repitios possible of all charaters from itertools import * for i in product(['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'],repeat = 8): b = (''.join(i)) print (b) How can I do something like that -…
1
vote
1 answer

Compute permutations following specific constraints

I want to store all feasible permutations for a target vector of size 24, that consists of (0,1). For memory efficiency I use the below: Test = data.table(permutations(n = 2,r = 12,v = c("zero","one"),repeats.allowed = T)) Test[, names(Test) :=…
1
vote
2 answers

Get permutation count

I searching for an algorithm which gives me the permutation count of the elements 1....n. If i define the cycle lengths. For example n := 4 -> permutation count 1,1,1,1 -> 1 read 4 cycles of length 1 leads to 1 permutation: …
1
vote
1 answer

Backtracking in Python with Stack Pop

I'm using backtracking to get permutations of non-duplicates nums list. E.g nums = [1, 2, 3], the output should be '[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]. I'm stuck on pop elements out from recursively stack. Anyone can help me what's…
1
2