Comments (1)
can anyone add code for lecture 79 :Trie & its Implementation code is missing
class TrieNode{
public:
char data;
TrieNode* children[26];
bool isterminal;
/** Initialize your data structure here. */
TrieNode(char data) {
this->data=data;
for (int i = 0; i < 26; i++) {
children[i] = NULL;
}
isterminal=false;
}
};
class Trie {
public:
TrieNode *root;
Trie(){
root= new TrieNode('\0');
}
/** Inserts a word into the trie. */
void insert(string word) {
insertword(root,word);
}
void insertword(TrieNode* root,string word){
if(word.length()==0){
root->isterminal=true;
return;
}
int index=word[0]-'a';
TrieNode* child;
if(root->children[index]!=NULL){
child=root->children[index];
}
else{
child=new TrieNode(word[0]);
root->children[index]=child;
}
insertword(child,word.substr(1));
}
/** Returns if the word is in the trie. */
bool search(string word){
return searchword(root,word);
}
bool searchword(TrieNode* root,string word){
if(word.length()==0){
return root->isterminal;
}
int index=word[0]-'a';
TrieNode* child;
if(root->children[index]!=NULL){
child=root->children[index];
}
else{
return false;
}
return searchword(child,word.substr(1));
}
bool start(TrieNode* root, string word){
if(word.length()==0){
return true;
}
int index=word[0]-'a';
TrieNode* child;
if(root->children[index]!=NULL){
child=root->children[index];
}
else{
return false;
}
return start(child,word.substr(1));
}
/** Returns if there is any word in the trie that starts with the given prefix. */
bool startsWith(string prefix) {
return start(root,prefix);
}
};
from codehelp-dsa-busted-series.
Related Issues (20)
- Code for 1402 leetcode not present HOT 1
- Missing codes
- Dsa sheet HOT 1
- Logical error in "copying the rest of second array elements" in the Lecture 20 -> mergeSortedArray.cpp
- fibonnaci series in recursion HOT 1
- Lecture 9 maxmin.cpp HOT 3
- Lecture number 39 permutation code not available HOT 1
- Lec6 : DecToBin is not working
- Please Upload all codes
- Please upload the code HOT 1
- graph
- DSA
- i have updated the merge list code for linked list day 6,please accept the pull request
- Reverse a Linked List in K group Question updated answer w.r.t Coding ninjas HOT 1
- Decimal to Binary Bug HOT 3
- homework
- If condition is not correct . You write in if condition ( if(this->next != NULL) ) , but correct this position ( if(this->next == NULL) ) . You write in if condition not equal but correct is equal to NULL HOT 1
- Book allocation
- Arranging files in order
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codehelp-dsa-busted-series.