Class StringInterleaving
java.lang.Object
topics.divideconquer.stringinterleaving.StringInterleaving
String Interleaving
Checks if string C is formed by an interleaving of strings A and B by recursively breaking the problem down into smaller sub-problems (advancing character pointers).
Pedagogical Value
This pure recursive approach acts as the mathematical bridge between Greedy and Dynamic Programming:
- Unlike Greedy, it does not get trapped by ambiguity. If characters from A and B both match C, it branches and explores both possibilities.
- Unlike Dynamic Programming, it does not memorize past results. This leads to overlapping sub-problems being recalculated multiple times.
- Time Complexity: O(2^(N+M)) in the worst case (Exponential due to branching).
- Space Complexity: O(N+M) - Bounded by the maximum depth of the call stack.
- Author:
- vicegd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisInterleaved(String a, String b, String c) Public wrapper method to initialize the recursion safely.
-
Constructor Details
-
StringInterleaving
public StringInterleaving()
-
-
Method Details
-
isInterleaved
-