feat: Implement Levenshtein distance and BFS #63
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces implementations and corresponding test cases for two algorithms: Levenshtein Distance (edit distance) and Breadth-First Search (BFS). The changes include the addition of well-documented algorithm implementations and comprehensive test coverage to ensure correctness and handle edge cases.
Levenshtein Distance Algorithm:
algorithms/dp/levenshtein-distance/levenshteinDistance.ts
: Added a function to compute the Levenshtein distance between two strings using dynamic programming. The function calculates the minimum number of single-character operations (insertions, deletions, or substitutions) required to transform one string into another.algorithms/dp/levenshtein-distance/levenshteinDistance.test.ts
: Added test cases to validate the correctness of the Levenshtein distance function, covering identical strings, empty strings, single operations, complex cases, and case sensitivity.Breadth-First Search (BFS) Algorithm:
algorithms/search/bfs/bfs.ts
: Implemented the BFS algorithm to calculate the shortest path distances and predecessors for path reconstruction. Also added a helper functionreconstructPath
to reconstruct the shortest path from a source vertex to a target vertex using the BFS results.algorithms/search/bfs/bfs.test.ts
: Added test cases for the BFS algorithm, covering scenarios such as simple graphs, disconnected graphs, invalid start vertices, single-vertex graphs, tree structures, cyclic graphs, and performance on large graphs. Also included tests for thereconstructPath
function to validate correct path reconstruction and handling of unreachable vertices.