Wednesday, January 1, 2014

Permutation of two String in ordered form

Objective: Generate permutation of two string in ordered form. e.g. if "abc" and "def" is two strings, we need to generate all permutation having these two string characters the only condition if "a" come before "b" then its must come before "b" in the permutations.
i.e. "adebfc", "abcdef", "daebcf" and so on are permutation of these string.

Approach: As we can see either we start with first string or second string, but we need to maintain each string character order in our permutation.

In general, we can say that all permutation either start with first string character or second string character.

i.e. if "abc" and "def" is two strings then, 

perumation("abc", "def") = ("a" + permutation("bc", "def")) and ("d" + permutation("abc", "ef")

Solution: Java Code

 

No comments:

Post a Comment