[algogeeks] Re: function to print all permutations of a string

2006-07-21 Thread Ranjit
This is in Java == public class Permute { public static void main(String[] args) { permute("", "ABCD"); } public static void permute(String parent, String s) { if (s.length() == 2) { System.out.println(parent + s);

[algogeeks] Re: hi..plz solve this..

2006-07-07 Thread Ranjit
Yet another approach. If instance size is n, A B C D a b c d 1. swap the element at n/2 and n-1 A B C c a b D d 2. shift "a" and "b" A B a b C c D d Now the instance size is n/2 (A B a b) Recursively perform steps 1. and 2. on it. The swaps are constant only the shifts are a function of n.