From 99b27b0733e608d81a9005715d391376d617f6f9 Mon Sep 17 00:00:00 2001 From: Aakash Panchal <51417248+Aakash-Panchal27@users.noreply.github.com> Date: Sat, 23 May 2020 14:39:24 +0530 Subject: [PATCH] Update Trie.md --- articles/Akash Articles/md/Trie.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/articles/Akash Articles/md/Trie.md b/articles/Akash Articles/md/Trie.md index 5572655..2f3b9ff 100644 --- a/articles/Akash Articles/md/Trie.md +++ b/articles/Akash Articles/md/Trie.md @@ -71,7 +71,7 @@ And therefore representation of trie containing string "act" will be as below. Now, observe the trie below, which contains two strings "act" and "ace". -![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/7.jpg=s800) +![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/7(1).jpg) Note that the node representing character `c` in the above trie, in magnified sense would look as below: @@ -85,7 +85,7 @@ Therefore, we are not creating any new node until we need one and **Trie is a ve Now, observe the trie below, which contains three strings `"act"`, `"ace"` and `"cat"`. -![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/9.jpg=s800) +![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/9(1).jpg) Let's see proper algorithm to insert a string in a trie. @@ -116,13 +116,13 @@ Can you figure out, how can we check whether the given string is present in trie For example, if you are searching `"aco"` in the trie below, then how will you do? -![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/9.jpg=s800) +![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/9(1).jpg) **Can you see, why `isEndofString` is needed?** Observe the trie given below and try to search whether `"on"` is present or not. -![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/10.jpg=s800) +![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/10(1).jpg) If you don't have `isEndofString` variable, then you will not be able to correctly check whether `on` is present or not. Because it is prefix of `once`. @@ -151,7 +151,7 @@ bool search(trie_node* root, string s) How will you delete `"ace"` from the trie below? -![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/9.jpg=s800) +![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/9(1).jpg) Things to take care about while you are deleting a string from the trie, 1. It should not affect any other string present in the trie. @@ -280,7 +280,7 @@ It is easy implemention, but with single downside. Therefore, use as per the req How will you find the number of words(strings) present in the trie below? -![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/9.jpg=s800) +![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/9(1).jpg) Ultimately, It means to find the total number of nodes having `true` value of `isEndofString`. Which can be easily done using recursive traversal of all the nodes present in the trie. @@ -340,7 +340,7 @@ How will you design autocompletion feature using Trie? For example, we have stored C++ keywords in a trie. Now, when you type `"n"` it should show all keywords starting from `"n"`. For simplicity only keywords starting from `"n"` are shown in the trie below, -![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/12.jpg=s800) +![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/12(1).jpg) How will you print all keywords starting from `"n"`? OR how will you print all keywords having `"n"` as prefix? @@ -426,4 +426,4 @@ struct trie_node Below image shows a typical trie structure for dictionary. -![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/13.jpg=s800) +![enter image description here](https://github.com/KingsGambitLab/Lecture_Notes/blob/master/articles/Akash%20Articles/md/Images/Trie/13(1).jpg)