Practice objective questions
for quick revision and examination
preparation. Try answering each question
before revealing the answer.
📚 Data Structures
📖 Unit 5
🎯 MCQs
Data Structures - Unit-5
1
What is the time complexity of the Brute Force Pattern Matching algorithm in the worst-case scenario?
AO(n)
BO(m)
CO(n + m)
DO(nm)
Correct AnswerO(nm)
2
In the context of Brute Force Pattern Matching, what does 'n' represent?
AThe length of the pattern
BThe length of the text
CThe number of matches found
DThe number of comparisons made
Correct AnswerThe length of the text
3
Which of the following best describes the Brute Force Pattern Matching algorithm?
AIt pre-processes the pattern to improve matching efficiency.
BIt matches the pattern against the text by checking for a match starting at each position in the text.
CIt uses a hash function to match the pattern with the text.
DIt requires additional memory proportional to the size of the pattern.
Correct AnswerIt matches the pattern against the text by checking for a match starting at each position in the text.
4
In Brute Force Pattern Matching, what happens if a mismatch is found?
AThe algorithm tries to match the next character of the pattern.
BThe pattern is shifted by one position in the text and the matching process starts again.
CThe text is pre-processed again.
DThe algorithm terminates immediately.
Correct AnswerThe pattern is shifted by one position in the text and the matching process starts again.
5
What is a major disadvantage of the Brute Force Pattern Matching algorithm?
AIt cannot handle large patterns.
BIt is too complex to implement.
CIt has a high time complexity in the worst-case scenario.
DIt requires additional space equal to the size of the text.
Correct AnswerIt has a high time complexity in the worst-case scenario.
6
When is the Brute Force Pattern Matching algorithm considered efficient?
AWhen the pattern is significantly longer than the text.
BWhen the pattern and the text are of similar length.
CWhen the pattern is short and the alphabet size is large.
DWhen multiple patterns need to be matched in the same text.
Correct AnswerWhen the pattern is short and the alphabet size is large.
7
Which of the following is true about the Brute Force Pattern Matching algorithm?
AIt requires pre-processing of the text.
BIt is the most efficient pattern matching algorithm in all cases.
CIt does not require any additional memory.
DIt can be optimized to skip some comparisons.
Correct AnswerIt does not require any additional memory.
8
What is the space complexity of the Brute Force Pattern Matching algorithm?
AO(1)
BO(n)
CO(m)
DO(nm)
Correct AnswerO(1)
9
What aspect of the Boyer-Moore algorithm makes it perform faster than the Brute Force Pattern Matching algorithm in many cases?
AThe use of a prefix table
BThe use of hash functions
CThe use of Bad Character and Good Suffix heuristics
DThe use of dynamic programming
Correct AnswerThe use of Bad Character and Good Suffix heuristics
10
What is the best-case time complexity of the Boyer-Moore Pattern Matching algorithm?
AO(n/m)
BO(n + m)
CO(n)
DO(m)
Correct AnswerO(n/m)
11
What does the Bad Character Heuristic in the Boyer-Moore algorithm do?
AIt shifts the pattern by one position when a mismatch occurs.
BIt shifts the pattern to align the last occurrence of the mismatched character in the pattern with the text.
CIt skips alignments that would result in a mismatch.
DIt pre-processes the pattern to find all bad characters.
Correct AnswerIt shifts the pattern to align the last occurrence of the mismatched character in the pattern with the text.
12
What does the Good Suffix Heuristic in the Boyer-Moore algorithm do?
AIt shifts the pattern based on the information gathered from the matched part of the pattern.
BIt compares the characters from the start of the pattern.
CIt ignores the suffix of the pattern.
DIt shifts the pattern by the length of the good suffix.
Correct AnswerIt shifts the pattern based on the information gathered from the matched part of the pattern.
13
Which of the following is true about the preprocessing phase of the Boyer-Moore algorithm?
AIt only computes the bad character table.
BIt only computes the good suffix table.
CIt computes both the bad character and good suffix tables.
DNo preprocessing is done in Boyer-Moore algorithm.
Correct AnswerIt computes both the bad character and good suffix tables.
14
In the context of the Boyer-Moore algorithm, what is the significance of the rightmost occurrence of a character?
AIt determines how the pattern should be aligned upon a mismatch.
BIt is used to compute the good suffix table.
CIt indicates the end of the pattern.
DIt is used to start the search from the right end of the pattern.
Correct AnswerIt determines how the pattern should be aligned upon a mismatch.
15
What is the worst-case time complexity of the Boyer-Moore Pattern Matching algorithm?
AO(n/m)
BO(n + m)
CO(n)
DO(mn)
Correct AnswerO(n + m)
16
Why is the Boyer-Moore algorithm generally faster than other pattern matching algorithms for long patterns?
ABecause it always processes every character of the text.
BBecause it does not process every character of the text in the worst case.
CBecause it uses extra memory to store the pattern.
DBecause it uses a hash function to match the pattern with the text.
Correct AnswerBecause it does not process every character of the text in the worst case.
17
What is the key concept behind the KMP algorithm that improves its efficiency compared to brute force pattern matching?
ASkipping comparisons based on partial matches
BUsing a hash function to match the pattern
CShifting the pattern by the length of the mismatch
DRecursively dividing the text into smaller parts
Correct AnswerSkipping comparisons based on partial matches
18
What does the prefix table (also known as the failure function or LPS array) in the KMP algorithm store?
AThe length of the longest prefix which is also a suffix for each substring of the pattern
BThe index of the next character to be compared in the text
CThe number of characters to be skipped for each mismatch
DThe hash values of all the prefixes of the pattern
Correct AnswerThe length of the longest prefix which is also a suffix for each substring of the pattern
19
What is the time complexity of the preprocessing phase (building the prefix table) in the KMP algorithm?
AO(n)
BO(m)
CO(n + m)
DO(m^2)
Correct AnswerO(m)
20
During the pattern matching phase, if a mismatch occurs at position m in the pattern and position n in the text, how does the KMP algorithm proceed?
AIt starts matching again from the beginning of the pattern.
BIt shifts the pattern by m positions and continues matching.
CIt uses the prefix table to determine the next position in the pattern to compare.
DIt reverses the pattern and starts matching again.
Correct AnswerIt uses the prefix table to determine the next position in the pattern to compare.
21
What is the worst-case time complexity of the KMP Pattern Matching algorithm?
AO(n/m)
BO(n + m)
CO(n)
DO(mn)
Correct AnswerO(n + m)
22
In the KMP algorithm, if the prefix table at a position i has a value k, what does it imply?
AThe next character to match in the text is at position k.
BThe next character to match in the pattern is at position k.
CThe length of the longest proper prefix which is also a suffix up to position i is k.
Dk characters should be skipped in the text.
Correct AnswerThe length of the longest proper prefix which is also a suffix up to position i is k.
23
How does the KMP algorithm handle the occurrence of a mismatch?
ABy backtracking in the text
BBy backtracking in the pattern
CBy using the prefix table to skip unnecessary comparisons in the pattern
DBy restarting the search from the next character in the text
Correct AnswerBy using the prefix table to skip unnecessary comparisons in the pattern
24
Why is the KMP algorithm considered efficient for pattern matching in strings?
AIt never reexamines a character in the text that has already been examined.
BIt uses a binary search mechanism.
CIt sorts the pattern and the text before matching.
DIt compares the pattern and text character by character without skipping.
Correct AnswerIt never reexamines a character in the text that has already been examined.
25
What is the primary advantage of using a standard trie for storing strings?
AEfficient memory usage
BFast search times for prefixes
CIn-order traversal of strings
DQuick sort of strings
Correct AnswerFast search times for prefixes
26
In a standard trie, each node typically represents what?
AA full string from the root to the node
BA single character
CThe end of a string
DA hash value of the string
Correct AnswerA single character
27
What is the main difference between a standard trie and a compressed trie (also known as a radix tree)?
ACompressed tries store entire strings at each node.
BCompressed tries combine a sequence of nodes with only one child into a single node.
CCompressed tries do not allow for the insertion of new strings.
DCompressed tries require more memory than standard tries.
Correct AnswerCompressed tries combine a sequence of nodes with only one child into a single node.
28
How does a compressed trie (radix tree) improve upon the space efficiency of a standard trie?
ABy eliminating all leaf nodes
BBy using a linked list instead of tree nodes
CBy merging nodes with single children into one node
DBy storing characters as bits instead of full characters
Correct AnswerBy merging nodes with single children into one node
29
What does a suffix trie of a string S represent?
AAll prefixes of S
BAll suffixes of S
CAll substrings of S
DAll anagrams of S
Correct AnswerAll suffixes of S
30
Which of the following operations can be performed efficiently using a suffix trie?
AFinding the longest repeated substring in a string
BSorting a list of unrelated strings
CFinding the minimum element in a numeric array
DBalancing a binary search tree
Correct AnswerFinding the longest repeated substring in a string
31
What is a potential drawback of using suffix tries?
AThey cannot store certain types of strings.
BThey can be space-inefficient due to storing all suffixes.
CThey do not support search operations.
DThey only work with binary alphabets.
Correct AnswerThey can be space-inefficient due to storing all suffixes.
32
In the context of suffix tries, how is the substring search operation performed?
ABy checking each node for the substring
BBy traversing the path that corresponds to the characters of the substring
CBy reversing the trie and searching from the end
DBy converting the trie into a suffix array and searching
Correct AnswerBy traversing the path that corresponds to the characters of the substring
Fill in the Blanks
33
The ________ algorithm is the simplest method where the pattern is slid over the text one character at a time.
Correct AnswerBrute Force
34
The Brute Force algorithm can be inefficient because it does not ________ any information from the text characters.
Correct Answerreuse
35
The ________ algorithm uses the bad character rule and the good suffix rule to improve the efficiency of pattern matching.
Correct AnswerBoyer-Moore
36
In the Boyer-Moore algorithm, the bad character rule shifts the pattern by aligning the last occurrence of a mismatched character in the pattern with its occurrence in the ________.
Correct Answertext
37
The ________ algorithm preprocesses the pattern to create an LPS (longest proper prefix which is also suffix) array to avoid unnecessary comparisons.
Correct AnswerKnuth-Morris-Pratt (KMP)
38
The time complexity of the Brute Force algorithm is generally O(nm) where n is the length of the text and m is the length of the ________.
Correct Answerpattern
39
The Boyer-Moore algorithm performs best when the alphabet size is ________, as it reduces the chance of a match with the bad character rule.
Correct Answerlarge
40
The KMP algorithm improves the time complexity to O(n + m) by not re-comparing characters that are already known to ________.
Correct Answermatch
41
In the Boyer-Moore algorithm, the good suffix rule shifts the pattern such that the best matching prefix aligns with the suffix in the ________ that has been matched so far.
Correct Answertext
42
A Trie is a tree-like data structure that stores a dynamic set of strings. Each node in a Trie represents a single ________ of a string.
Correct Answercharacter
43
In a Trie, all the descendants of a node have a common ________.
Correct Answerprefix
44
The root node in a Trie represents an ________ string.
Correct Answerempty
45
In a Trie, a node that represents the end of a string or a word is often marked with a special ________ marker.
Correct Answerend-of-word
46
The time complexity of searching for a key in a Trie is O(m), where m is the length of the key, making it very efficient compared to other data structures like ________ or ________.
Correct Answerarrays, linked lists
47
Tries are particularly efficient for ________ operations, allowing for rapid re-traversal of shared key parts.
Correct Answerprefix-based search
48
In a Trie, nodes may have as many children as there are characters in the ________, making it different from a binary search tree.
Correct Answeralphabet
49
Tries are commonly used in applications like auto-complete, spell checking, and IP routing, where quick retrieval of ________ is crucial.
Correct Answerstrings
50
To save space, a common variation of Trie is ________ Trie, which merges nodes with a single child.
Correct Answercompressed
51
Unlike regular Tries, ________ Tries store all the suffixes of a given string and are used in various string-searching algorithms.