Skip to content

Add Trie data structure implementation #44

Description

@Suvanwita

The Lua algorithms repository already includes several fundamental data structures such as graphs, heaps, segment trees, sorted sets, k-d trees, and union-find. One classic structure that is still missing is a Trie (prefix tree).

Why this should be added

  • Trie is a core data structure for prefix-based lookups and dictionary-style operations.
  • It complements the existing collection of structures in src/data_structures.
  • It is useful for string matching, autocomplete, prefix searches, and dictionary membership checks.

Proposed implementation

Add a Lua implementation under src/data_structures/ with support for:

  • inserting strings or keys
  • checking whether a key exists
  • searching by prefix
  • returning all keys under a prefix (optional but useful)
  • basic traversal/iteration operations

Suggested API shape

A minimal API could look like:

  • Trie.new()
  • :insert(key)
  • :contains(key)
  • :has_prefix(prefix)
  • :keys_with_prefix(prefix) or similar

This would make the repository more complete and provide a useful, widely applicable structure alongside the current implementations.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions