Skip to content

docs, test: fit edit_distance.cpp to contributing guidelines#3118

Open
rahulpaul-07 wants to merge 2 commits intoTheAlgorithms:masterfrom
rahulpaul-07:fix-edit-distance-guidelines
Open

docs, test: fit edit_distance.cpp to contributing guidelines#3118
rahulpaul-07 wants to merge 2 commits intoTheAlgorithms:masterfrom
rahulpaul-07:fix-edit-distance-guidelines

Conversation

@rahulpaul-07
Copy link
Copy Markdown

@rahulpaul-07 rahulpaul-07 commented Apr 3, 2026

Description of Change

This PR updates dynamic_programming/edit_distance.cpp to align with the modern contribution guidelines and significantly improves the algorithm's efficiency.

Changes:

  • Space Optimization: Refactored the core logic from O(m * n) to O(n) space complexity using a two-row dynamic programming approach.
  • Namespace Encapsulation: Wrapped the implementation in the dynamic_programming namespace to prevent global scope pollution.
  • Doxygen Documentation: Added full Doxygen-style headers for the file and functions, including Wikipedia references and parameter descriptions.
  • Security Gating: Added a defensive check to prevent memory exhaustion (DoS) for inputs exceeding 10,000 characters.
  • Automated Testing: Replaced interactive std::cin inputs with a comprehensive suite of automated assert tests covering edge cases (empty strings, identical strings, and case sensitivity).
  • Code Quality: Cleaned up headers, removed using namespace std;, and ensured strict type safety with static_cast.

Related Issue:

Fixes #2456

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.

[FIX] Pre-existing algorithms do not fit the contribution guidelines

1 participant