954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

permutations of STRING Vs First n natural numbers

hi....well this is my first post in this community...i hope people here will help me in my doubts...
I am an intermediate level programmer of c++...
i have a doubt regarding the permutations of a given string and permutations of first N natural numbers...
i have written a program for printing all the possible permutations of first N natural numbers..in the order of their indexes.....means if the user enters the index...the program will also tell him the i-th permutation....i havent used recursion...but when i searched here i saw the program for permuting a given string using recursion....i want to know whether the two problems are same or different...
And why the permutation problem is so important...that it is asked in interviews...kindly help me out...i can post my code and the algorithm i have followed for permutation of first n numbers...(if anybody want)

thanks & regards...
Rajat

rajatC
Junior Poster
109 posts since Dec 2007
Reputation Points: 14
Solved Threads: 7
 
i want to know whether the two problems are same or different

The problem is the same. Solutions are worked out in different manner.

Apart from this, I could not make out from your post what problem you are facing. Please mention if I've misunderstood something.

You said this:i have a doubt regarding the permutations of a given string and permutations of first N natural numbers...

But afterwards, you didn't mention the doubt.

Jishnu
Posting Pro
518 posts since Oct 2006
Reputation Points: 193
Solved Threads: 25
 

well u already answered one of my questions.....the other is that why is it to so important..

well i also want to tell u that the program which i have made works fine upto first 8 natural number's permutations...but when i try it for 9 or number greater than 9 then it takes lot of time to print all the permutations...factorial 9>300000....so i wonder whta's the best solution possible till now...what's the time complexity of the best solution using recursion or some other efficient method...

rajatC
Junior Poster
109 posts since Dec 2007
Reputation Points: 14
Solved Threads: 7
 

I don't know about the best solution. But you can improve the existing program by using long int instead of int and also changing the memory model to large or huge.

Jishnu
Posting Pro
518 posts since Oct 2006
Reputation Points: 193
Solved Threads: 25
 

long int??? for what??? sorry i didnt get ur point..
i m using double to store the number of total permutation and an integer array[n] to store different permutations of n numbers...
And how will long int affect the running time of my program...

also changing the memory model to large or huge...
i m using Dev-C++..where does this model means??? how to change it??
help plz..

rajatC
Junior Poster
109 posts since Dec 2007
Reputation Points: 14
Solved Threads: 7
 
long int??? for what??? sorry i didnt get ur point.. i m using double to store the number of total permutation and an integer array[n] to store different permutations of n numbers...

Doubles are inexact. You can't have 2354.34 permutations. Therefore double is a bad choice.

And how will long int affect the running time of my program...

Floating point takes longer to compute. Granted in this program it may not make a noticeable difference...also changing the memory model to large or huge...
i m using Dev-C++..where does this model means??? how to change it??
It doesn't.Jishnu obviously thinks you're using a very old compiler.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

Yes, I thought so. Now, as he has specified, changing the memory model is inapplicable to this case.

Jishnu
Posting Pro
518 posts since Oct 2006
Reputation Points: 193
Solved Threads: 25
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You