#C176. Trie-Based Tag Search
Trie-Based Tag Search
Trie-Based Tag Search
You are given two lists: a list of tags and a list of query strings. Your task is to determine for each query string whether it exactly exists in the list of tags. This problem can be efficiently solved using the Trie data structure.
A Trie (or prefix tree) is a tree data structure that is typically used to store strings. In this problem, you will insert all the given tags into a Trie and then search for each query string in the Trie.
Note: The search should be case-sensitive, and partial matches do not count as valid.
The task requires you to implement two essential methods:
- insert: Insert a tag into the Trie.
- search: Check if a query string exactly exists in the Trie.
The answer will be evaluated based on correctness across several test cases.
inputFormat
The input is read from stdin and has the following format:
N ... (N tags) Q ... (Q queries)
Here, N
is the number of tags and Q
is the number of queries. Each tag and query is provided on a separate line. All strings are case-sensitive.
outputFormat
For each query, print True
if the query exactly exists in the tags; otherwise, print False
. Each result should be printed on a new line to stdout.
5
python
coding
algorithms
datastructures
trie
5
python
trie
graph
data
sorting
True
True
False
False
False
</p>