The thing is I have to use an N-ary tree, it's part of the assignment. And I don't want someone to write the code for me, I was asking which was a better way to handle it cause that depends how I write my code. What I'm having issues with is how to actually build it.
Say I'm connecting cat to dog with the below dictionary.
bag, bat, bog, bot, cat, cog, cot, dog, dot, eat, fan, fat, ham, hat, hot
First I rearranged it to correspond to cat, thus getting this.
cat, bat, cot, eat, fat, hat, bag, bot, cog, dot, fan, ham, hot, bog, dog
So, since all the ones that are one off are now at the beginning, we know that all the ones from bat to hat go under cat. The thing is that bat should point to bag and bot, but it should also point to eat, fat, and hat. That's the point I'm asking about.
What is the best way to handle this? While inserting, should I have it search through the nodes in the tree and add pointers to the others nodes that are one letter away? Or, should I insert all the words into the tree first and then go through and point to the nodes that are one letter away from said node?