Class StringInterleavingGenerator
java.lang.Object
topics.backtracking.stringinterleaving.StringInterleavingGenerator
String Interleaving Generator
Instead of verifying a single target string, this algorithm exhaustively generates EVERY possible valid interleaving of two strings, maintaining the relative order of their characters.
The Backtracking Paradigm
Notice the core pattern inside the recursive method:
- CHOOSE: We append a character to our current path.
- EXPLORE: We recurse deeper into the tree.
- UN-CHOOSE: We delete the character to backtrack and try a parallel branch.
- Time Complexity: O( (N+M)! / (N! * M!) ) - Combinatorial explosion.
- Space Complexity: O(N+M) for the recursion stack and string builder.
- Author:
- vicegd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGenerates all possible interleavings of two strings.
-
Constructor Details
-
StringInterleavingGenerator
public StringInterleavingGenerator()
-
-
Method Details
-
generateAllInterleavings
-