xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

算法数据结构之 Trie 前缀树 All In One

算法数据结构之 Trie 前缀树 All In One

In computer science, a trie (/ˈtraɪ/, /ˈtriː/ ⓘ), also known as a digital tree or prefix tree,is a specialized search tree data structure used to store and retrieve strings from a dictionary or set.
Unlike a binary search tree, nodes in a trie do not store their associated key.
Instead, each node's position within the trie determines its associated key, with the connections between nodes defined by individual characters rather than the entire key.

在计算机科学中,trie(/ˈtraɪ/, /ˈtriː/ ⓘ),也称为数字树前缀树,是一种专门用于存储检索字典或集合中字符串的搜索树数据结构。
二叉搜索树不同,trie 中的节点不存储其关联的键。
相反,每个节点在 trie 中的位置决定了其关联的键,节点之间的连接由单个字符而非整个键定义。

image

image

https://en.wikipedia.org/wiki/Trie

demos

  1. Implement Trie (Prefix Tree)

A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.


class Trie {
    constructor() {
        
    }

    insert(word: string): void {
        
    }

    search(word: string): boolean {
        
    }

    startsWith(prefix: string): boolean {
        
    }
}

/**
 * Your Trie object will be instantiated and called as such:
 * var obj = new Trie()
 * obj.insert(word)
 * var param_2 = obj.search(word)
 * var param_3 = obj.startsWith(prefix)
 */

https://leetcode.com/problems/implement-trie-prefix-tree/

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

Trie / 前缀树

image

image

image

image

image

https://time.geekbang.org/course/detail/100019701-67642



refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2025-11-17 13:24  xgqfrms  阅读(8)  评论(3)    收藏  举报