Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a trie by storing each string as a path of character links, marking the node where each complete word ends. To autocomplete, follow the typed prefix from the root, then search below that node for completions. Finding the prefix takes O(L) time for a prefix of length L; finding and ordering its matches takes additional work that depends on how many results you need and how they are ranked.

How a trie represents words

A trie, also called a prefix tree, shares the beginning of words that have the same prefix. Each node holds a mapping from characters to child nodes, plus a boolean such as is_word that indicates whether the path to that node is itself a stored word.

The terminal flag is essential. If the dictionary contains both “app” and “apple,” the node reached after “app” must be marked as a word even though it also has a child for “l.” Without the flag, an implementation could either miss “app” or mistake every prefix for a complete word.

Build the basic trie

The following language-neutral pseudocode uses a map of character-to-child links. It assumes each input has already been normalized according to your application’s matching rules.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Insert a word

  1. Create a root node with an empty child map and is_word = false.
  2. Start at the root. For each character in the word, create a child node if that character’s edge does not exist, then follow the edge.
  3. After consuming the final character, set the current node’s is_word flag to true.
insert(word):
    node = root
    for character in word:
        if character not in node.children:
            node.children[character] = new Node()
        node = node.children[character]
    node.is_word = true

Inserting a word of length L takes O(L) time under the usual assumption that a child-map lookup is constant time. It creates at most L new nodes, and fewer when the word shares prefixes with existing entries.

Find the node for a prefix

Use the same one-character-at-a-time walk, but return no match as soon as a required edge is absent. An empty prefix naturally resolves to the root.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
find_prefix_node(prefix):
    node = root
    for character in prefix:
        if character not in node.children:
            return no_match
        node = node.children[character]
    return node

Exact search uses this walk and then checks is_word. A starts-with check only needs to know whether the walk succeeds. Both take O(L) time for an input of length L.

Return autocomplete suggestions

After finding the prefix node, traverse its descendants and emit a word whenever a visited node is terminal. Carry the characters along the path, or append and remove characters as a recursive traversal moves down and back up the trie.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
completions(prefix, limit):
    start = find_prefix_node(prefix)
    if start is no_match:
        return []

    results = []
    visit(node, path):
        if node.is_word:
            results.append(path)
        for character, child in node.children:
            visit(child, path + character)

    visit(start, prefix)
    return results up to limit

This simple traversal is useful when dictionary size and result volume are manageable. Its total cost is not just O(L): after the prefix walk, the algorithm must visit relevant descendants and construct the returned strings. A short, broad prefix can have a large subtree, so claiming every autocomplete query takes O(L) would be misleading.

A limit can reduce work only when traversal order matches the result policy. If suggestions must be sorted by popularity, alphabetical order, recency, or another ranking, stopping at the first K words encountered in an arbitrary traversal does not guarantee the best K results.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Choose how suggestions are ranked

Traverse, then rank

For a straightforward implementation, collect matching words and sort them by a score, such as search frequency. This is easy to reason about and accommodates changing ranking rules, but it may visit many descendants and spend time ranking results even when the interface displays only a few.

Cache top results at each node

For read-heavy workloads with a fixed result cap, each node can maintain its best K completions. Once the prefix walk reaches a node, the query reads that cached list instead of traversing the entire subtree. The DSA Handbook tutorial describes this as approximately O(L + k) for a prefix of length L and k returned entries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

The trade-off is shifted to writes and memory: caches consume space across nodes, and inserting a word or changing its score may require refreshing caches along its path. The tutorial characterizes this update work as O(L × K) for a word of length L and cache cap K. Keep the ranking comparator and tie-break rule consistent whenever caches are rebuilt or updated.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Pick a node representation that fits your alphabet

Representation What it means Trade-off
Child map Store only outgoing character edges present at each node. Supports broader character sets without allocating every possible edge, but map structures have overhead.
Fixed child array Reserve one slot per character in a known, bounded alphabet. Simple and direct when the alphabet is truly fixed; wastes slots or fails to represent characters outside that set.
Compressed or radix trie Merge runs of single-child nodes into edges labeled with character sequences. Can reduce node overhead on long single-child paths, at the cost of more complex edge splitting and merging.

These are design options, not guaranteed speed rankings. A fixed array can work well for a strict alphabet such as lowercase a–z, but that constraint must be deliberate. A reference implementation that lowercases input and uses a–z should not be treated as a general Unicode policy.

Define text normalization before indexing

Insertion and query processing must apply compatible normalization, or a word can be stored under a path that a user cannot reach with the corresponding query. Decide how the application handles case, Unicode normalization, spaces, punctuation, and character boundaries. Depending on the language and product, trie edges may represent bytes, Unicode code points, or grapheme clusters; those choices are not interchangeable for every user-visible notion of a character.

  • Choose whether matching is case-sensitive or case-insensitive, and apply the same rule to stored entries and typed prefixes.
  • Decide whether canonically equivalent Unicode text should match after normalization.
  • Specify whether spaces and punctuation are valid transitions or should be removed or transformed.
  • Use one consistent definition of a character across insertion, lookup, and result reconstruction.

Compare trie designs with other approaches

Design Query behavior Main costs Best fit
Basic trie with subtree traversal O(L) to reach the prefix; completion work depends on visited descendants and results. Simple to implement; broad prefixes can require substantial traversal and ranking. Small or moderate dictionaries, especially when simplicity and straightforward updates matter.
Trie with per-node top-K cache Prefix walk plus cached-result access, approximately O(L + k) for k returned entries as described by the DSA Handbook tutorial. Additional cache memory; insertions and score changes refresh caches. Read-heavy autocomplete with a bounded result count.
Compressed or radix trie Prefix operations follow path fragments rather than one node per character. More complex edge splitting and merging; can reduce nodes on single-child runs. When node memory is a constraint.
Sorted array plus segment tree Dhruv Matani’s 2021-10-29 arXiv preprint reports O(k log n) query time for k ranked results from n candidates. Requires maintaining sorted phrases and an auxiliary index; update behavior differs from a trie. A candidate for ranked lookup when data is static or updates are controlled.

Matani’s asymptotic result describes a particular algorithm, not a universal benchmark against tries. Compare candidate designs using the workload that matters: query volume, update frequency, memory budget, result cap, ranking and tie-breaking policy, alphabet requirements, and implementation complexity.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What published corpus figures do—and do not—show

A 2021 Columbia University course project report by Thang Nguyen and Siddharth Pittie says its cleaned dataset, built from NeurIPS 2015 submissions, contained 1,737,937 words (11 MB). The report says the authors duplicated that dataset six times to make a 10,427,550-word (63 MB) test corpus. It identifies the test machine as an Intel Core i7-8700K at 3.70 GHz, with 12 cores and 32 GB of RAM. Those figures describe that report’s corpus and test setup; they are not a general estimate of dictionary size or a benchmark for your application.

Make the choice against your workload

  • Start with a basic trie if you need simple prefix lookup and can tolerate traversal of matching subtrees.
  • Add top-K caches when reads dominate, result requests are bounded, and the memory and update costs are acceptable.
  • Consider a compressed trie when node overhead is a material constraint and the added implementation complexity is worthwhile.
  • Evaluate a sorted-array and segment-tree approach for ranked, relatively stable datasets rather than assuming a trie is always the best substrate.
  • Measure query and update behavior on representative data and hardware before making a performance decision; published asymptotic costs do not determine real-world speed by themselves.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.