本文へスキップ

リソース · ガイド・記事

Trie

接頭辞木(トライ)を説明しています。ノードの位置がそのキーを表し、すべての子孫がそのノードの接頭辞を共有するため、文字列をキーとする検索に向いています。

確認日

元のサイトを開く: Trie (元のサイトを新しいタブで開きます)

このトピックを練習木 の問題で練習用面接官を開きます。

ロードマップに追加

取り組んでいるロードマップにこのリソースを追加できます。自分用の追加リソースとして表示され、ロードマップの手順は変わらず、記録した手順数にも数えられません。

出典コンテンツの言語:英語

Read this in other languages: 简体中文, Русский, Português, Українська, 한국어 In computer science, a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is a kind of search tree—an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings. Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string. Values are not necessarily associated with every node. Rather, values tend only to be associated with leaves, and with some inner nodes that correspond to keys of interest. For the space-optimized presentation of prefix tree, see compact prefix tree.

PrepKit の概要

この概要は PrepKit 編集部がソースリポジトリをもとに執筆・確認したもので、リソース本文の引用ではありません。

対象
ソースにレベルの記載はありません
形式
リファレンス

扱っている内容

  • キーを保持する場所について、トライと二分探索木の違い
  • 根は空文字列で、値は葉と一部の内部ノードに保持されること、およびコンパクトな接頭辞木への言及

使い方

PrepKit の学習アドバイスであり、ソースの主張ではありません。

insert、search、startsWith を実装し、そのうえでトライを使って、指定した接頭辞を持つ保存済みの単語をすべて返してください。

範囲と制約

ページに操作、計算量、オートコンプリートの例はなく、実装の詳細は Wikipedia と YouTube のリンクに任されています。

利用方法と形式

GitHub の trekhleb/javascript-algorithms(MIT)にある短い README で、5つの翻訳へのリンクがあります。英語で、無料です。

PrepKit が 2026/10/02 に確認しました。 リソースの出典のコミット: 85293e3e2b88

この概要の根拠
  • src/data-structures/trie/README.md

この項目を掲載しているページ

PrepKit ニュースレターを受け取る

任意です。PrepKit の利用には必要ありません。

メールアドレスの取り扱いについて