Skip to content

Conversation

@codomposer
Copy link
Contributor

Add Manacher's Algorithm for Longest Palindromic Substring

Summary

This PR implements Manacher's Algorithm, a linear-time O(n) algorithm for finding the longest palindromic substring in a string. This is a significant improvement over the naive O(n²) approach.

What's Added

  • Algorithm Implementation (Algorithms/Strings/ManachersAlgorithm.cs):

    • FindLongestPalindrome() - Returns the longest palindromic substring
    • FindLongestPalindromeWithDetails() - Returns palindrome with position details
    • IsPalindrome() - Checks if entire string is a palindrome
    • Comprehensive inline documentation explaining the algorithm's logic
  • Comprehensive Test Suite (Algorithms.Tests/Strings/ManachersAlgorithmTests.cs):

    • 28 test cases covering:
      • Odd and even-length palindromes
      • Edge cases (empty, single character, no palindromes)
      • Special characters and numeric strings
      • Performance validation with long strings
  • Documentation:

    • Updated README.md with link to the new algorithm
    • Detailed docstrings explaining key concepts and complexity
    • Step-by-step algorithm breakdown with examples

Algorithm Details

  • Time Complexity: O(n) - Each character examined at most twice
  • Space Complexity: O(n) - For transformed string and radius array
  • Reference: "A New Linear-Time On-Line Algorithm for Finding the Smallest Initial Palindrome of a String" by Glenn Manacher (1975), Journal of the ACM

Testing

All tests pass successfully:

  • ✅ 28 new Manacher's Algorithm tests
  • ✅ 12,252 total repository tests passing
  • ✅ 0 warnings, 0 errors
  • ✅ StyleCop compliance maintained

Checklist

  • I have performed a self-review of my code
  • My code follows the style guidelines of this project
  • 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
  • Comments in areas I changed are up to date
  • I have added comments to hard-to-understand areas of my code
  • I have made corresponding changes to the README.md

@codomposer codomposer requested a review from siriak as a code owner November 5, 2025 00:30
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.85%. Comparing base (411763c) to head (39c5130).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #554      +/-   ##
==========================================
+ Coverage   96.82%   96.85%   +0.02%     
==========================================
  Files         286      287       +1     
  Lines       11753    11861     +108     
  Branches     1687     1706      +19     
==========================================
+ Hits        11380    11488     +108     
  Misses        237      237              
  Partials      136      136              

☔ 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.

1 participant