Question

Write an algorithm for generating all the permutations of(1,2,3,...,n) exactly once.

Write an algorithm for generating all the permutations of(1,2,3,...,n) exactly once.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

  • Function permute(s,l,r)
    • if(l==r)
      • For i=0 to length(s)
        • PRINT s[i]+", ";
      • EndFor
    • Else
      • For i=l to r do
        • SWAP(s[l],s[i]);
        • permute(s,l+1,r);
        • SWAP(s[l],s[i]);
      • EndFor
    • EndIf
  • EndFunction

Call function as

permute('1234....n',0,n-1)

It will print all permutations of 1,2,....n exactly once

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write an algorithm for generating all the permutations of(1,2,3,...,n) exactly once.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT