TrieNode Class: Represents individual nodes with children and isEndOfWord attributes and core methods:
addChild: Adds a child node for the given character and returns the child node.
getChild: Retrieves the child node for the given character, or null if no such child exists.
hasChild: Checks if a child node for the given character exists.
Trie Class: Implements core methods:
insert: Inserts a word into the Trie.
search: Searches for a word in the Trie.
startsWith: Finds words starting with a given prefix.
delete: Deletes a word from the Trie and recursively removes nodes associated with a word.
getWords(): Retrieves all words in the Trie.
traverseTrieNode: Recursively collect all words starting from a given node.
Unit Tests: TrieTest.php includes PHPUnit tests to validate the correct behavior of insertion, search, deletion, and retrieval functions.
GitHub Actions
All tests and workflows (in my forked repository) have passed.
Contents:
TrieNode Class: Represents individual nodes with
children
andisEndOfWord
attributes and core methods:addChild
: Adds a child node for the given character and returns the child node.getChild
: Retrieves the child node for the given character, or null if no such child exists.hasChild
: Checks if a child node for the given character exists.Trie Class: Implements core methods:
insert
: Inserts a word into the Trie.search
: Searches for a word in the Trie.startsWith
: Finds words starting with a given prefix.delete
: Deletes a word from the Trie and recursively removes nodes associated with a word.getWords()
: Retrieves all words in the Trie.traverseTrieNode
: Recursively collect all words starting from a given node.Unit Tests:
TrieTest.php
includesPHPUnit
tests to validate the correct behavior of insertion, search, deletion, and retrieval functions.GitHub Actions
All tests and workflows (in my forked repository) have passed.
Reference
Data Structures and Algorithms in C++, 2nd Edition