Why do we need data structure and an Example (Word Dictionary)

Cheetah , Rose , Pineapple , Orange , Lily , Cat

Does words above make any sense ?
It probably does those are words. But it’s just too random. But what if I wrote the same words like this?

Example

A, AN , AND, ANT

Suppose we want to store these 4 words somewhere, What would be the easiest way to put it? Yes a list of strings would do just fine. It would look something like this on the memory

A
AN
AND
ANT

Implementation

Now I’d try to write this down as generalized as possible without favoring a single programming language.But here’s a warning for newbies , I’m not going to explain my code syntax . My target audience isn’t beginners.

  1. List of Children
  2. A Character
  3. If it is Word[Will explain later]
+AddWordToDictionary(string word):void+IsValidWord(String word):boolean+SearchByPrefix(string prefix):List<string>

There’s much room for improvement in the data structure. That I’ll leave for another time. This data structure has one major drawback I’ll mention it here. Although this structure will save a lot of space and make searches easier. It can’t be used to find words of “N” length in an optimized way.Why? I’l leave the readers to think about it. If you think it’s possible to do otherwise please let me know in the comments.

In case anyone’s interested in testing out the code, the code is available here.

Author — “How to Make A Game” / Apress, Springer Nature | Head Of Unity Department at Brain Station 23 Limited | Co-Founder of Capawcino Cat Cafe