but I can't use any other things like numbers and stuffs like %^&$,... in my program since I don't know how big an array I will need. |
An array of size (1 << CHAR_BIT) is big enough to hold all possible values of a char, but such an array of pointers will, in most platforms, use 1 or 2 kilobytes of memory per node.
I'd have to loop through all the child nodes in the worst case, would that still be faster than an AVL tree |
Let's assume that checking for existence of a character in a trie node needs a linear search.
A trie requires up to k*n character comparisons to check for existence, where n is the length of the query and k is the size of the alphabet. An AVL requires up to log m string comparisons where m is the number of nodes in the tree.
AVL: O(log m) over size of structure, O(n log m) over size of query
Trie: O(1) over size of structure, O(n) over size of query
However, note that a trie with a linear search at each node can be beaten by an AVL tree if the word count is very small, because the constant factor is bigger for the trie than for the AVL tree.
A trie that can find the next node in O(1) is always faster than the AVL tree, but uses more memory.