Listen

No amount of pointers, no number of guidelines can prepare you to become a good listener. The tendency to listen must come from within you. It is a habit that takes time to develop, but once…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Insert Words

Trie is an approach to search or insert a string in complexity of O(n) where n is length of searched or inserted word.

Basic Structure

Starting by Initialization of the root node. Let’s say

Now we will do 2 basic operations to understand Trie data structure better.

Starting with our first operation:

We will use recursion for inserting any word into our data structure.

You can also do this by for or while loop.

2. Search

We will also use recursion for searching any word into our data structure.

You can also do this by for or while loop.

By this two function we arrive at the complete code as:

Explaining this only on the basis of above given code.

Inserting words “mug” into our data structure by following steps:

Take initial instance of LettersMap as wordsMap

Now insert letter ‘m’

Now insert letter ‘u’

Now insert letter ‘g’

Now declare it is the end of a word

Similarly, inserting ‘mud’ word into data structure.

This is how we can insert data into this data structure.

This is how our data structure looks like:

I am writing this post because i found Trie data structure very exciting but not much information about it in Typescript and Javascript.

For Typescript, I have written another version of it. Click here to see

FOUND USEFUL, PLEASE CLAP

Add a comment

Related posts:

Who Do You See When You Look in The Mirror?

When I look in the mirror, I see a privileged young woman born into a vessel that happens to be white. I stare at my Italian skin, bronzed shoulders, and freckled face, as I wonder how different my…

Latin Love Lessons

A tale of innocence lost. Three girls enjoy their first holiday without adults. Anna learns some more sexual and dating firsts

Eat that frog with a pomodoro

Procrastination is the avoidance of doing a task that needs to be accomplished by a certain deadline and pomodoro is a technique that we can use to overcome procrastination. As i come to know about…