{"id":16601965,"url":"https://github.com/iampavangandhi/wordcompositionproblem","last_synced_at":"2025-10-13T11:43:53.504Z","repository":{"id":125319009,"uuid":"319083005","full_name":"iampavangandhi/WordCompositionProblem","owner":"iampavangandhi","description":"📄 Word Composition Problem - To find words constructed by concatenating shorter words also found in the file.","archived":false,"fork":false,"pushed_at":"2020-12-06T16:51:40.000Z","size":481,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-16T08:28:00.226Z","etag":null,"topics":["composition-problem","datastructures","datastructuresandalgorithm","trie","word-composition"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iampavangandhi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-12-06T16:50:35.000Z","updated_at":"2020-12-23T19:08:20.000Z","dependencies_parsed_at":"2023-08-11T02:47:28.643Z","dependency_job_id":null,"html_url":"https://github.com/iampavangandhi/WordCompositionProblem","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iampavangandhi/WordCompositionProblem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iampavangandhi%2FWordCompositionProblem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iampavangandhi%2FWordCompositionProblem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iampavangandhi%2FWordCompositionProblem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iampavangandhi%2FWordCompositionProblem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iampavangandhi","download_url":"https://codeload.github.com/iampavangandhi/WordCompositionProblem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iampavangandhi%2FWordCompositionProblem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014804,"owners_count":26085594,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["composition-problem","datastructures","datastructuresandalgorithm","trie","word-composition"],"created_at":"2024-10-12T00:19:49.583Z","updated_at":"2025-10-13T11:43:53.487Z","avatar_url":"https://github.com/iampavangandhi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Word Composition Problem\n\nTo find words constructed by concatenating shorter words also found in the file.\n\n## Input (files)\n\n- words.txt\n- words1.txt\n\n## Output\n\n```\nratcatdogcat catsdogcats\n\nethylenediaminetetraacetates ethylenediaminetetraacetate\n```\n\n## Approach\n\nUsed Trie data structure its a special tree that stores strings. Maximum number of children of a node is equal to size of alphabet. Trie supports search, insert and delete operations in O(k) time where k is length of key/word. This is obviously faster than BST and Hashing. and we can efficiently do Prefix search.\n\nFirst `searchConcatWords` function read the file text and constructed Trie from the text/words using insert method present inside `trie.js` then used `findLongestString` function inside a loop to find the longest strings. Then `prefixChecker` function checks the string whether it was constructed using small words found in the Trie or not by checking the length of the result using find method present inside `trie.js` if greater than 1 increment the index and after loop ends return `true` If not there are two cases: (1) If the index is equal to 1 that means concat word is not found in the Trie and return `false` (2) Else it cuts the previous part and recursively call `prefixChecker` function again.\n\n### Example of `prefixChecker` :\n\n| Calling word       | Output                                               | Result                                           |\n| ------------------ | ---------------------------------------------------- | ------------------------------------------------ |\n| trie.find(\"c\")     | `[ 'catxdogcatsrat', 'catsdogcats', 'cats', 'cat' ]` | Increment index and return `true` after loop     |\n| trie.find(\"catsd\") | `[ 'catsdogcats' ]` and `index !== 1`                | Recursive call to `prefixChecker` with `dogcats` |\n| trie.find(\"hippo\") | `[ 'hippopotamuses' ]` and `index === 1`             | Concat word not found and returns `false`        |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiampavangandhi%2Fwordcompositionproblem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiampavangandhi%2Fwordcompositionproblem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiampavangandhi%2Fwordcompositionproblem/lists"}