Which of the following is the correct definition of a Trie data structure?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which of the following operations is NOT typically supported by a Trie?
The time complexity for searching a string in a Trie of N nodes is:
Which of the following problems can be efficiently solved using Tries?
What will be the output of the following code?
#include <iostream>
#include "Trie.h"
int main() {
Trie trie;
trie.insert("apple");
trie.insert("banana");
trie.insert("cat");
std::cout << trie.search("apple") << std::endl;
std::cout << trie.search("dog") << std::endl;
std::cout << trie.search("cat") << std::endl;
return 0;
}
What will be the output of the following code?
#include <iostream>
#include "Trie.h"
int main() {
Trie trie;
trie.insert("apple");
trie.insert("banana");
trie.insert("cat");
std::cout << trie.startsWith("a") << std::endl;
std::cout << trie.startsWith("b") << std::endl;
std::cout << trie.startsWith("d") << std::endl;
return 0;
}
What will be the output of the following code?
#include <iostream>
#include "Trie.h"
int main() {
Trie trie;
trie.insert("apple");
trie.insert("banana");
trie.insert("cat");
trie.remove("apple");
std::cout << trie.search("apple") << std::endl;
std::cout << trie.search("banana") << std::endl;
return 0;
}
What will be the output of the following code?
#include <iostream>
#include "Trie.h"
int main() {
Trie trie;
trie.insert("apple");
trie.insert("banana");
trie.insert("cat");
std::cout << trie.countPrefixes("a") << std::endl;
std::cout << trie.countPrefixes("b") << std::endl;
std::cout << trie.countPrefixes("ca") << std::endl;
return 0;
}
What will be the output of the following code?
#include <iostream>
#include "Trie.h"
int main() {
Trie trie;
trie.insert("apple");
trie.insert("banana");
trie.insert("cat");
std::cout << trie.longestPrefix("applesauce") << std::endl;
std::cout << trie.longestPrefix("carrot") << std::endl;
std::cout << trie.longestPrefix("catnip") << std::endl;
return 0;
}
Given a list of strings, how can you efficiently build an auto-complete feature using a Trie?
You are given a Trie data structure and a word. Implement the 'search' function that returns 'true' if the word exists in the Trie and 'false' otherwise. The signature of the function is: 'bool search(TrieNode* root, string word)'.
Given a Trie data structure, how can you efficiently count the number of strings that have a given prefix? Implement the 'countPrefix' function that returns the count of strings with a given prefix. The signature of the function is: 'int countPrefix(TrieNode* root, string prefix)'.
Given a Trie data structure and a list of strings, how can you efficiently find the longest duplicate substring in the list? Implement the 'longestDuplicateSubstring' function that returns the longest duplicate substring. The signature of the function is: 'string longestDuplicateSubstring(vector<string>& words)'.
You are given a Trie data structure and a word. Implement the 'remove' function that removes the word from the Trie. The signature of the function is: 'void remove(TrieNode* root, string word)'.