Skip to content

Conversation

kokatesaurabh
Copy link

Here's the content formatted as a README file:

# Regular Expression Matching

## 📋 Problem Description
This implementation solves the Regular Expression Matching algorithm (LeetCode #10) with support for `'.'` (any single character) and `'*'` (zero or more of preceding element) operators. The solution ensures the entire input string must match the pattern, not just a substring.

## 🚀 Features Implemented
- **Two DP implementations**:
  - Recursive with memoization (top-down)
  - Iterative tabulation (bottom-up)
- **Comprehensive input validation** with meaningful error messages
- **Full pattern validation** ensuring `'*'` always follows valid characters
- **Extensive test coverage** with 40+ test cases

## 🧩 Algorithm Details
- **Time Complexity**: O(m × n) where m = string length, n = pattern length
- **Space Complexity**: O(m × n) for DP table
- **Approach**: Dynamic Programming with state tracking of string and pattern indices

## 📝 Key Features
✅ Handles `'.'` wildcard character  
✅ Handles `'*'` quantifier (zero or more occurrences)  
✅ Validates pattern format and input constraints  
✅ Covers edge cases (empty strings, complex patterns)  
✅ Matches LeetCode problem specifications exactly  

## 🧪 Test Coverage
- Basic exact matching scenarios
- Dot wildcard functionality
- Star quantifier patterns
- Complex pattern combinations
- Edge cases and boundary conditions
- Invalid input validation
- LeetCode example test cases
- Cross-validation between both implementations

## 📁 Files Added

src/main/java/com/thealgorithms/dynamicprogramming/RegularExpressionMatching.java
src/test/java/com/thealgorithms/dynamicprogramming/RegularExpressionMatchingTest.java


## 🔍 Example Usage
```java
// Basic matching
RegularExpressionMatching.isMatch("aa", "a");        // false
RegularExpressionMatching.isMatch("aa", "a*");       // true
RegularExpressionMatching.isMatch("ab", ".*");       // true

// Complex patterns
RegularExpressionMatching.isMatch("aab", "c*a*b");   // true
RegularExpressionMatching.isMatch("mississippi", "mis*is*p*."); // false

📊 Validation

✅ Follows project coding standards and checkstyle
✅ Includes comprehensive JavaDoc documentation
✅ Passes all existing tests in the repository
✅ No breaking changes to existing functionality
✅ Proper error handling and input validation

🎯 Use Cases

  • String pattern matching in text processing
  • Input validation with complex patterns
  • Educational demonstration of dynamic programming
  • Foundation for more complex regex implementations

This implementation provides a robust, well-tested solution that follows the project's contribution guidelines and adds value to the algorithms collection.


Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant