cf
cf
Struct TrueNode{
int subTrieStrings;
Node* children[26];
}
int find(string & prefix, int pos, Node* root){
if(root == NULL) return 0;
if(pos == prefix.size())
return root->subTrie strings;
*/
/*
#include <iostream>
#include <string>
using namespace std;
struct Node {
int subTrieStrings;
Node* children[26];
Node() {
subTrieStrings = 0;
for (int i = 0; i < 26; ++i)
children[i] = nullptr;
}
};
class Trie {
private:
Node* root;
public:
Trie() {
root = new Node();
}
int main() {
Trie trie;
trie.insert("apple");
trie.insert("app");
trie.insert("banana");
trie.insert("bat");
cout << "Frequency of prefix 'a': " << trie.find("a") << endl;
cout << "Frequency of prefix 'ap': " << trie.find("ap") << endl;
cout << "Frequency of prefix 'ban': " << trie.find("ban") << endl;
cout << "Frequency of prefix 'c': " << trie.find("c") << endl;
return 0;
}
*/
struct Node{
int strings;
bool end;
Node* children[26];
}
Node* create Node(){
Node* node = new Node;
node -> end = false;
node -> strings = 0;
for(int i=0; i<26; i++){
node->children[i] = NULL:
return node;
}
void insert(string & word, int pos, Node*curr){
if(pos == word.size()){
curr->end = true;
return;
}
curr->strings++;
if(!curr->children[word[pos]-'a']);
curr->children[word[pos]-'a'] = createNode();
insert(word, pos+1, curr->children[word[pos]-'a');
}
}
#include <iostream>
#include <string>
using namespace std;
struct Node {
int strings;
bool end;
Node* children[26];
Node() {
strings = 0;
end = false;
for (int i = 0; i < 26; ++i)
children[i] = nullptr;
}
};
Node* createNode() {
Node* node = new Node;
node->end = false;
node->strings = 0;
return node;
}
int main() {
Node* root = createNode();
insert(word1, 0, root);
insert(word2, 0, root);
insert(word3, 0, root);
return 0;
}
*************DELETION in tries**********
tc-o(nl)
sc-o(nl)