Skip to content

Conversation

princegupta22
Copy link

Description

This PR adds the Z Algorithm implementation for efficient pattern matching in strings.

Algorithm Details

  • Time Complexity: O(n + m) where n is text length and m is pattern length
  • Space Complexity: O(n + m)
  • Category: String algorithms
  • Use Cases: Pattern matching, string searching, prefix computation

What's Included

  • Complete Z Algorithm implementation with:
    • computeZArray() - computes Z array for a string
    • search() - finds all occurrences of pattern in text
    • Proper JavaDoc documentation
    • Working example in main() method
    • Edge case handling

Testing

  • Code compiles without errors
  • Main method demonstrates correct functionality
  • Handles edge cases (null, empty strings)
  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 0% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.57%. Comparing base (e6cb96f) to head (2cfe6d7).

Files with missing lines Patch % Lines
...ain/java/com/thealgorithms/strings/ZAlgorithm.java 0.00% 47 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6651      +/-   ##
============================================
- Coverage     75.74%   75.57%   -0.18%     
- Complexity     5771     5772       +1     
============================================
  Files           702      703       +1     
  Lines         19770    19817      +47     
  Branches       3832     3841       +9     
============================================
+ Hits          14975    14976       +1     
- Misses         4215     4262      +47     
+ Partials        580      579       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants