Trie Multiple choice Questions and Answers (MCQs)

 

 Buy/Download all MCQ Ebook   >>>Click Here<<<

Trie Multiple choice Questions and Answers (MCQs)

Click on any option to know the CORRECT ANSWERS

Question 1
Trie is also known as .....
A
Digital Tree
B
Treap
C
Binomial Tree
D
2-3 Tree


Question 1 Explanation: 
Trie is a very useful data structure which is based on the prefix of a string. Trie is used to represent the "Retrieval" of data and thus the name Trie. And it is also known as a digital tree.

Question 2
What traversal over trie gives the lexicographical sorting of the set of the strings?
A
postorder
B
preorders
C
inorder
D
level order


Question 2 Explanation: 
In trie, we store the strings in such a way that there is one node for every common prefix. Therefore the inorder traversal over trie gives the lexicographically sorted set of strings.

Question 3
Which of the following is the efficient data structure for searching words in dictionaries?
A
BST
B
Linked List
C
Balancded BST
D
Trie


Question 3 Explanation: 
In a BST, as well as in a balanced BST searching takes time in order of mlogn, where m is the maximum string length and n is the number of strings in tree. But searching in trie will take O(m) time to search the key.

Question 4
Which of the following special type of trie is used for fast searching of the full texts?
A
Ctrie
B
Hash tree
C
Suffix tree
D
T tree


Question 4 Explanation: 
Suffix tree, a special type of trie, contains all the suffixes of the given text at the key and their position in the text as their values. So, suffix trees are used for fast searching of the full texts.

Question 5
Following code snippet is the function to insert a string in a trie. Find the missing line.

private void insert(String str) { TrieNode node = root; for (int i = 0; i < length; i++) { int index = key.charAt(i) - 'a'; if (node.children[index] == null) node.children[index] = new TrieNode(); ..... } node.isEndOfWord = true; }
A
node = node.children[index];
B
node = node.children[str.charAt(i + 1)];
C
node = node.children[index++];
D
node = node.children[index++];


Question 5 Explanation: 
In the insert() method we search if the string is present or not. If the string is not present, then we insert the string into the trie. If it is present as the prefi, x we mark the leaf node. So, correct option is node = node.children[index];.

There are 5 questions to complete.