{"id":22192349,"url":"https://github.com/mzusin/mz-trie","last_synced_at":"2025-03-24T20:44:59.207Z","repository":{"id":207737815,"uuid":"719967630","full_name":"mzusin/mz-trie","owner":"mzusin","description":"Typescript implementation of trie/digital tree/radix tree/prefix tree/suffix tree.","archived":false,"fork":false,"pushed_at":"2023-11-18T12:45:43.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-30T01:18:24.390Z","etag":null,"topics":["digital-tree","longest-common-prefix","prefix-tree","suffix-tree","suffix-trees","trie","trie-data-structure","trie-tree","tries"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/mzusin.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}},"created_at":"2023-11-17T09:39:23.000Z","updated_at":"2023-11-18T12:45:58.000Z","dependencies_parsed_at":"2023-11-17T10:54:49.568Z","dependency_job_id":null,"html_url":"https://github.com/mzusin/mz-trie","commit_stats":null,"previous_names":["mzusin/mz-trie"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzusin%2Fmz-trie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzusin%2Fmz-trie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzusin%2Fmz-trie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzusin%2Fmz-trie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mzusin","download_url":"https://codeload.github.com/mzusin/mz-trie/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245351761,"owners_count":20601090,"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":["digital-tree","longest-common-prefix","prefix-tree","suffix-tree","suffix-trees","trie","trie-data-structure","trie-tree","tries"],"created_at":"2024-12-02T12:22:23.740Z","updated_at":"2025-03-24T20:44:59.171Z","avatar_url":"https://github.com/mzusin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Trie\n\nTypescript implementation of trie/digital tree/radix tree/prefix tree/suffix tree. \n\n![](docs/trie.png)\n\n## Definition\n**Trie** (derived from re**trie**val) is a type of k-ary **search tree** used for storing and searching a specific string from a set. It is used to store a large amount of strings. The **pattern matching** can be done efficiently using tries.\n\n- Using trie, the key can be searched in **O(M)** time, where M is the **maximum string length**. However, the penalty is the storage requirements.\n- Tries take less space when they contain a large number of short strings, as nodes are shared between the keys.\n\n## Usage Examples\n- Autocompletion.\n- The longest prefix.\n- Spell-checking software.\n\n## Interfaces\n\n```ts\nexport interface INode {\n    children: Map\u003cstring, INode\u003e;\n    isEndOfWord: boolean;\n}\nexport interface ITrie {\n    insert: (key: string) =\u003e void;\n    remove: (key: string) =\u003e void;\n    search: (key: string) =\u003e boolean;\n    isEmpty: (node?: INode) =\u003e boolean;\n    getLeavesCount: (node?: INode) =\u003e number;\n    getHeight: (node?: INode) =\u003e number;\n    printTrie: () =\u003e string;\n    log: () =\u003e string;\n    getWords: () =\u003e string[];\n}\n\nexport const trie: (keys?: string[]) =\u003e ITrie;\nexport const suffixTree: (text: string) =\u003e ITrie;\n```\n\n### Documentation\n\n```ts\nconst _trie = trie(['orange', 'apple']);\n\nconsole.log(_trie.search('orange')); // true or false\n\n_trie.insert('potato');\n_trie.remove('potato');\n\nconsole.log(_trie.log());\nconsole.log(_trie.getWords()); // ['orange', 'apple']\nconsole.log(_trie.printTrie());\nconsole.log(_trie.longestCommonPrefix());\n```\n\n### Suffix Tree\n\n```ts\nconst st = suffixTree('banana');\nconsole.log(st.search('apple')); // false\nconsole.log(st.search('banana')); // true\nconsole.log(st.search('anana')); // true\nconsole.log(st.search('nana')); // true\nconsole.log(st.search('ana')); // true\nconsole.log(st.search('na')); // true\nconsole.log(st.search('a')); // true\n```\n\n**Suffix tree usage**\n\n- Pattern Searching\n- Finding the longest repeated substring\n- Finding the longest common substring\n- Finding the longest palindrome in a string \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzusin%2Fmz-trie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmzusin%2Fmz-trie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzusin%2Fmz-trie/lists"}