Trie 树核心原理
一、Trie 树定位Trie 树(前缀树 / 字典树)是专为字符串设计的树形结构,核心价值是通过 “前缀共享” 减少内存冗余,同时实现 O (k)(k 为字符串长度)的插入 / 查询效率,尤其适合 “前缀相关场景”(如自动补全、拼写检查)。 二、核心结构:节点设计与前缀共享1. 节点结构体Trie 的最小单元是节点,需存储子节点映射和单词结尾标记,C++ 中用结构体实现最简洁: 123456789struct TrieNode { // 子节点:两种实现方案(按需选择) // 方案1:数组(仅适用于固定小字符集,如小写字母,速度快) TrieNode* children[26] = {nullptr}; // 方案2:哈希表(字符集不确定时用,如含数字/符号,灵活) // unordered_map<char, TrieNode*> children; bool isEnd = false; //...


Recent Posts
Categories
- C++80
- C-Code23
- CMake3
- CS501
- Computer-Networking40
- Computer-Organization1
- Data Structures and Algorithms1
- Data-Structures6
- Essay1
- Essays4
- Foundational Syntax and Core Concepts3
- Git3
- HTTP2
- Interview7
- Lcov2
- Leetcode132
- Linux40
- Linux Internals2
- List1
- Lists1
- MQTT8
- MYSQL3
- MySQL1
- Operating-Systems7
- PKGCONF1
- Redis14
- STL3
- UML1
- XML1
- lock1
- practice problems1
- 代码提交1
- 函数模板2
- 工厂模式2
- 类图1
- 编译1
- 设计模式8
- 链表1
Archives
- 2026年01月 2
- 2025年12月 11
- 2025年11月 10
- 2025年10月 8
- 2025年09月 20
- 2025年08月 8
- 2025年07月 8
- 2025年06月 8
- 2025年05月 8
- 2025年04月 8
- 2025年03月 8
- 2025年02月 8
- 2025年01月 8
- 2024年12月 9
- 2024年11月 7
- 2024年10月 10
- 2024年09月 10
- 2024年08月 10
- 2024年07月 8
- 2024年06月 8
- 2024年05月 9
- 2024年04月 9
- 2024年03月 9
- 2024年02月 7
- 2024年01月 9
- 2023年12月 8
- 2023年11月 9
- 2023年10月 8
- 2023年09月 6
- 2023年08月 7
- 2023年07月 9
- 2023年06月 8
- 2023年05月 11
- 2023年04月 8
- 2023年03月 8
- 2023年02月 8
- 2023年01月 8
- 2022年12月 9
- 2022年11月 14
- 2022年10月 10
- 2022年09月 7
- 2022年08月 6
- 2022年07月 8
- 2022年06月 10
- 2022年05月 7
- 2022年04月 7
- 2022年03月 4
- 2022年02月 5
- 2022年01月 5
Website Info
Article Count :
410
Runtime :
Total Word Count :
684.8k
Last Update :