although these are strings, but for me it looks like certain categories and subcategories, such as fruits, fresh fruits, citrus fruits, etc.
If this is the case, you can instead implement the Tree data structure. This would be most effective for a search operation.
since Tree has a parent-child structure, there is a root node and a child node. You may have a structure like this:
(0) (1) (2) fruit |_____citrus | |_____lemon | |_____orange | |_____freshly |_____apple |_____
in this structure, let's say if you want to look for citrus fruits, you can just go to citrus fruits and list all your children. And finally, you can build the full name by combining the name as a path from root to leaf.
source share