{"id":22513878,"url":"https://github.com/emahtab/edit-distance","last_synced_at":"2025-03-28T01:29:27.817Z","repository":{"id":79526406,"uuid":"225362272","full_name":"eMahtab/edit-distance","owner":"eMahtab","description":"Edit Distance Problem","archived":false,"fork":false,"pushed_at":"2019-12-02T13:25:24.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T03:25:50.267Z","etag":null,"topics":["edit-distance","levenshtein-distance","problem-solving"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-02T11:45:44.000Z","updated_at":"2020-01-16T12:45:01.000Z","dependencies_parsed_at":"2023-05-10T17:15:55.207Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/edit-distance","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fedit-distance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fedit-distance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fedit-distance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fedit-distance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/edit-distance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245952163,"owners_count":20699440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["edit-distance","levenshtein-distance","problem-solving"],"created_at":"2024-12-07T03:14:46.970Z","updated_at":"2025-03-28T01:29:27.406Z","avatar_url":"https://github.com/eMahtab.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Edit Distance - Levenshtein distance\nGiven two strings string1 and string2, find the minimum number of operations required to convert string1 to string2.\n\nYou have the following 3 operations permitted on a string:\n\n1. Insert a character\n2. Delete a character\n3. Replace a character\n\ne.g.\nInput: string1 = \"horse\", string2 = \"ros\"\n\nOutput: 3\n\nExplanation: \n\nhorse -\u003e rorse (replace 'h' with 'r')\n\nrorse -\u003e rose (remove 'r')\n\nrose -\u003e ros (remove 'e')\n\n## Solution\nWe can solve this problem using Dynamic Programming\n\n### Dynamic Programming : Bottom-Up (Tabulation) Approach \nWe start filling the dpTable, row by row, and we fill all the columns in a single row, before moving to next row. By doing this we are solving the subproblems, which will help us, to get to the result of our actual problem.\n\nIf string1 is empty, then it will take as many insertion operations as the length of the second string (string2), to make string1 equal to string2. So the values in first row, will be increment by 1 at each cell because the length of second string (string2) is increasing by 1 with each column. \n\nSimilarly If string2 is empty, then it will take as many deletion operations as the length of the first string (string1), to make string1 equal to string2. So the values in first column, will be increment by 1 at each cell because the length of first string (string1) is increasing by 1 with each column. \n\n```java\npublic class App {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"Edit Distance :\" + minDistance(\"abc\", \"cbad\"));\n\t}\n\n\tpublic static int minDistance(String word1, String word2) {\n\t\tint rows = word1.length();\n\t\tint columns = word2.length();\n\n\t\tint[][] dpTable = new int[rows + 1][columns + 1];\n\t\tfor (int j = 0; j \u003c= columns; j++) {\n\t\t\tdpTable[0][j] = j;\n\t\t}\n\t\tfor (int i = 0; i \u003c= rows; i++) {\n\t\t\tdpTable[i][0] = i;\n\t\t}\n\n\t\tfor (int i = 1; i \u003c= rows; i++) {\n\t\t\tfor (int j = 1; j \u003c= columns; j++) {\n\t\t\t\tif (word1.charAt(i - 1) == word2.charAt(j - 1)) {\n\t\t\t\t\tdpTable[i][j] = dpTable[i - 1][j - 1];\n\t\t\t\t} else {\n\t\t\t\t\tint min = Math.min(dpTable[i - 1][j], dpTable[i][j - 1]);\n\t\t\t\t\tdpTable[i][j] = 1 + Math.min(min, dpTable[i - 1][j - 1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn dpTable[rows][columns];\n\t}\n}\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fedit-distance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fedit-distance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fedit-distance/lists"}