473,806 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

algorithm for finding permutation of characters

I am not asking for code but wanted help with understanding the
algorithm to permute all characters of a string.
say string is "ABCD"

I want to know the algorithm for finding all permutations of the given
string, without recursion and with recursion.
Jul 22 '05 #1
4 5638
m sergei wrote:
I am not asking for code but wanted help with understanding the
algorithm to permute all characters of a string.
say string is "ABCD"

I want to know the algorithm for finding all permutations of the given
string, without recursion and with recursion.


There is nothing as "the algorithm" to do this. There is a vast multitude
of different algorithms that have been proposed. D.E. Knuth has a chapter
on this, which you can download:

http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz

It is about 60 pages.
Best

Kai-Uwe Bux
Jul 22 '05 #2
On 28 Jun 2004 19:30:14 -0700 in comp.lang.c++, se********@yaho o.com (m
sergei) wrote,
I am not asking for code but wanted help with understanding the
algorithm to permute all characters of a string.
say string is "ABCD"


By "the algorithm" do you mean std::next_permu tation?

Jul 22 '05 #3

"m sergei" <se********@yah oo.com> wrote in message
news:86******** *************** ***@posting.goo gle.com...
I am not asking for code but wanted help with understanding the
algorithm to permute all characters of a string.
say string is "ABCD"

I want to know the algorithm for finding all permutations of the given
string, without recursion and with recursion.


A non-recursive algorithm can be found by looking at the
std::next_permu tation code, which will be in the header file <algorithm>
that comes with your compiler (or possibly in another header file that is
included by <algorithm>, search around you'll find it).

john
Jul 22 '05 #4
one way of doing it with recursion. should do all chars in a,b,c,d,e as so:
a-b, a-c, a-d, a-e
b-c, b-d, b-e
c-d, c-e
d-e

for (int i=0; i<numofchars; i++) {
for (int j=(i+1);j<numof chars;j++) {
// do something with the char at i, and the char at j
}
}

"m sergei" <se********@yah oo.com> wrote in message
news:86******** *************** ***@posting.goo gle.com...
I am not asking for code but wanted help with understanding the
algorithm to permute all characters of a string.
say string is "ABCD"

I want to know the algorithm for finding all permutations of the given
string, without recursion and with recursion.

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2350
by: Mike | last post by:
Hello all, I'm looking for a free method to apply a one-way encryption to a 64-bit value in an ASP script. Does anyone have any links to existing code or at least a process that I can follow to develop it myself? Thanks! -- Mike
4
2287
by: jose luis fernandez diaz | last post by:
Hi, I want to write a function of four parameters. Each parameter can be of type long, double or string. For example: f(long, long, long, long); f(long, long, long, double); f(long, long, long, const string &); f(long, long, double, long); f(long, long, string, long);
8
10955
by: cayblood | last post by:
Hello, I have been interested in something kind of like the next_permutation from the STL algorithm library, except that I want it to find possible combinations of vector elements. Here is a more detailed example of what I want: Given a vector containing an arbitrary number of vectors, each of which contains an arbitrary number of elements, generate a new vector in which each element consists of one element taken from its corresponding...
16
2725
by: Mars | last post by:
I'm writing a program for listing all binary numbers of the same length with the same number of 1s. e.g. 0011 0101 0110 1001 1010 1100
3
7142
by: Jack Middleton | last post by:
Hi! I'm lookin for a faster permutation algorithm for matrices. I know that it can be done with multiplying a matrix with a permutation matrix. It just seems a waste to iterate through all those zeroes. Is there an algorithm for matrixes that is optimized just for permutations? The matrices that I use are fairly small (around 6*6) and I only use positive integers as elements. Thanks for help,
2
3883
by: all_my_trash | last post by:
Hello! I'm trying to write an algorithm which can fill an array with all the possible combinations of r out of n, without repetition (maximum combinations = n!/(r!(n-r)!)) However, my mathematical skills are insufficient - does anybody have such an algorithm for sharing? Regards,
12
6618
by: whitehatmiracle | last post by:
Dear Sir I couldnt quite figure out wat your permute function does exactly... could you please throw some light on it? void Permute(char *Perm, size_t n, size_t unchanged) { size_t outer = 0; size_t inner = 0; int temp = 0;
4
32087
prometheuzz
by: prometheuzz | last post by:
Hello (Java) enthusiasts, In this article I’d like to tell you a little bit about graphs and how you can search a graph using the BFS (breadth first search) algorithm. I’ll address, and hopefully answer, the following questions: • what is a graph? • how can a graph be represented as an ADT? • how can we search/walk through a graph using the BFS algorithm?
0
1493
by: 249740 | last post by:
Write a program that reads N phrases and determines if one phrase is a permutation of the other. For example: Phrase 1 is: “One World One Dream” Phrase 2 is: “World One One Dream”. Then the output should say that phrase 1 is permutation of phrase 2. Note that spaces/tabs are not counted as characters. Sample Input: 3 One World One Dream World One One Dream No World No Dream Sample Output: Phrase 1 is permutation of Phrase 2
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10618
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10371
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3850
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.