Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
String AlgorithmsEasy
Q1. What is string matching?
- A.Comparing two strings for equality only
- B.Finding occurrences of a pattern in text✓ Correct
- C.Sorting strings in alphabetical order
- D.Concatenating two strings end to end
Explanation
String matching (pattern matching) is the problem of finding all occurrences of a pattern string within a larger text string.
Report an error in this question
String AlgorithmsEasy
Q2. What is the brute force string matching time complexity for text of length n and pattern of length m?
- A.O(n)
- B.O(n + m)
- C.O(m)
- D.O(n × m)✓ Correct
Explanation
Brute force string matching checks the pattern at every position in the text, giving O(n × m) worst-case time complexity.
Report an error in this question
String AlgorithmsEasy
Q3. What is a suffix of a string?
- A.A substring starting from the beginning
- B.A rotated version of the string
- C.The first character of the string
- D.A substring ending at the last character✓ Correct
Explanation
A suffix is a substring that ends at the last character. For 'hello', suffixes include 'o', 'lo', 'llo', 'ello', 'hello'.
Report an error in this question
String AlgorithmsEasy
Q4. What is a substring?
- A.A rearrangement of string characters
- B.A contiguous sequence of characters within a string✓ Correct
- C.A string of exactly length 1 character
- D.Any characters from a string in any order
Explanation
A substring is a contiguous sequence of characters within a string. For example, 'bcd' is a substring of 'abcde'.
Report an error in this question
String AlgorithmsEasy
Q5. What is string concatenation?
- A.Splitting a string into parts
- B.Reversing a string entirely
- C.Joining two strings end to end✓ Correct
- D.Sorting characters in a string
Explanation
String concatenation joins two or more strings end to end to form a new string. For example, 'hello' + ' world' = 'hello world'.
Report an error in this question
String AlgorithmsEasy
Q6. What is a palindrome?
- A.A string with only repeated characters throughout
- B.A string with all unique characters
- C.A string with an even number of characters
- D.A string that reads the same forward and backward✓ Correct
Explanation
A palindrome is a string that reads the same forward and backward, such as 'racecar' or 'madam'.
Report an error in this question
String AlgorithmsMedium
Q7. What is the KMP (Knuth-Morris-Pratt) algorithm?
- A.A string compression algorithm for reducing text size
- B.A hash-based search method for substring matching tasks
- C.A pattern matcher using failure function to skip redundancy✓ Correct
- D.A comparison-based sorting algorithm for string arrays
Explanation
KMP preprocesses the pattern to build a failure function (partial match table) that allows it to skip redundant comparisons, achieving O(n + m) time.
Report an error in this question
String AlgorithmsEasy
Q8. What is a prefix of a string?
- A.The middle portion of the string
- B.A reversed version of the string
- C.The last character of the string
- D.A substring starting from the beginning✓ Correct
Explanation
A prefix is a substring that starts at the beginning of the string. For 'hello', prefixes include 'h', 'he', 'hel', 'hell', 'hello'.
Report an error in this question
String AlgorithmsEasy
Q9. What is an anagram?
- A.A palindrome of another word
- B.A prefix of another given word
- C.A substring of another word
- D.A rearrangement forming another word✓ Correct
Explanation
An anagram is formed by rearranging the characters of a word to create a new word, using all original letters exactly once (e.g., 'listen' and 'silent').
Report an error in this question
String AlgorithmsEasy
Q10. What is a subsequence of a string?
- A.A sequence derived by deleting characters keeping order✓ Correct
- B.A contiguous part of the original string
- C.A sorted version of the original string
- D.A reversed version of the original string
Explanation
A subsequence is formed by deleting zero or more characters from a string without changing the relative order of remaining characters.
Report an error in this question
String AlgorithmsEasy
Q11. How can you check if two strings are anagrams?
- A.Compare their lengths only for equality
- B.Check if they have the same first character
- C.Reverse one string and compare with the other
- D.Sort both strings and compare, or count frequencies✓ Correct
Explanation
Two strings are anagrams if they have the same character frequencies. This can be checked by sorting both (O(n log n)) or counting character frequencies (O(n)).
Report an error in this question
String AlgorithmsMedium
Q12. What is the longest palindromic substring problem?
- A.Finding the longest string in a collection
- B.Reversing a string to find palindromes
- C.Finding the longest contiguous palindrome substring✓ Correct
- D.Finding all palindromes in a given string
Explanation
The problem asks for the longest contiguous substring of a given string that reads the same forwards and backwards.
Report an error in this question
String AlgorithmsMedium
Q13. What is the Rabin-Karp algorithm?
- A.A divide and conquer string matching algorithm
- B.A string matching algorithm using rolling hashes✓ Correct
- C.A string sorting algorithm by character values
- D.A tree-based matching algorithm using tries
Explanation
Rabin-Karp uses a rolling hash to compute hash values of text substrings, comparing them with the pattern's hash for quick matching.
Report an error in this question
String AlgorithmsMedium
Q14. What is a rolling hash in Rabin-Karp?
- A.A hash that updates efficiently as the window slides✓ Correct
- B.A multi-level hash with cascading computation
- C.A hash that changes randomly each call
- D.A hash stored in a circular buffer structure
Explanation
A rolling hash efficiently updates the hash value when the window slides by one position, by removing the contribution of the outgoing character and adding the incoming one in O(1).
Report an error in this question
String AlgorithmsMedium
Q15. What is the time complexity of finding the longest palindromic substring using dynamic programming?
- A.O(n^3)
- B.O(n)
- C.O(n^2)✓ Correct
- D.O(n log n)
Explanation
The DP approach fills an n × n table, checking if each substring is a palindrome, taking O(n^2) time.
Report an error in this question
String AlgorithmsMedium
Q16. What is the time complexity of the KMP algorithm?
- A.O(n + m)✓ Correct
- B.O(m log n)
- C.O(n × m)
- D.O(n^2)
Explanation
KMP runs in O(n + m) time: O(m) for preprocessing the pattern and O(n) for searching through the text.
Report an error in this question
String AlgorithmsMedium
Q17. What is string hashing used for?
- A.Efficiently comparing strings via hash values✓ Correct
- B.Encrypting strings for secure storage
- C.Compressing strings to save disk space
- D.Sorting strings into alphabetical order
Explanation
String hashing computes hash values of strings for efficient comparison. It is used in pattern matching, duplicate detection, and many string problems.
Report an error in this question
String AlgorithmsMedium
Q18. What is the Boyer-Moore algorithm?
- A.A pattern matcher using bad character and good suffix rules✓ Correct
- B.A brute force matching algorithm for strings
- C.A string sorting algorithm by character frequency
- D.A compression algorithm for text data files
Explanation
Boyer-Moore compares the pattern from right to left and uses bad character and good suffix heuristics to skip portions of the text, often achieving sub-linear time in practice.
Report an error in this question
String AlgorithmsHard
Q19. What is the time complexity of the Boyer-Moore algorithm in the best case?
- A.O(n/m)✓ Correct
- B.O(n × m)
- C.O(n)
- D.O(n + m)
Explanation
In the best case, Boyer-Moore achieves O(n/m) time by skipping m characters at a time using the bad character heuristic.
Report an error in this question
String AlgorithmsHard
Q20. What is the number of distinct substrings of a string of length n?
- A.n(n+1)/2 minus sum(LCP)✓ Correct
- B.2^n (exponential count)
- C.n^2 (quadratic count)
- D.n! (factorial of n)
Explanation
The number of distinct substrings is n(n+1)/2 - sum(LCP), where LCP is the longest common prefix array of the suffix array. Total substrings minus duplicates.
Report an error in this question
String AlgorithmsHard
Q21. What is the Aho-Corasick algorithm?
- A.A multi-pattern matcher building a trie-based automaton✓ Correct
- B.A compression algorithm for pattern libraries
- C.A single pattern matching algorithm only
- D.A string sorting algorithm for multiple strings
Explanation
Aho-Corasick builds a trie-based automaton from multiple patterns and searches for all patterns simultaneously in the text in O(n + m + z) time, where z is the number of matches.
Report an error in this question
String AlgorithmsHard
Q22. What is a suffix automaton?
- A.An automaton that generates all suffixes
- B.A pattern matching machine for any text
- C.A minimal DFA recognizing all suffixes of a string✓ Correct
- D.A suffix tree variant with compressed nodes
Explanation
A suffix automaton is the smallest DFA that accepts exactly all suffixes of a string. It can be built in O(n) time and has at most 2n-1 states.
Report an error in this question
String AlgorithmsMedium
Q23. How is the Z-algorithm used for pattern matching?
- A.By hashing the pattern and comparing values
- B.By using a suffix tree of the text string
- C.By sorting the text characters first
- D.By concatenating pattern and text then computing Z-array✓ Correct
Explanation
The Z-algorithm concatenates pattern P, a separator, and text T (P$T), then computes the Z-array. Positions where Z[i] = |P| indicate pattern matches.
Report an error in this question
String AlgorithmsMedium
Q24. What is the Z-array of a string?
- A.An array where Z[i] is longest prefix match starting at i✓ Correct
- B.The reverse of the original string as array
- C.An array of character frequencies for the string
- D.An array of zeros for initialization
Explanation
The Z-array for a string S has Z[i] = length of the longest substring starting at position i that is also a prefix of S. It can be computed in O(n) time.
Report an error in this question
String AlgorithmsHard
Q25. What is the time complexity of building a suffix array using the DC3/skew algorithm?
- A.O(n log^2 n)
- B.O(n log n)
- C.O(n^2)
- D.O(n)✓ Correct
Explanation
The DC3 (difference cover) algorithm constructs a suffix array in O(n) time, which is optimal.
Report an error in this question
String AlgorithmsHard
Q26. What is the LCP (Longest Common Prefix) array?
- A.An array storing longest common prefix lengths between consecutive sorted suffixes✓ Correct
- B.An array storing character frequencies found within a given string
- C.An array storing the lengths of all strings within a collection
- D.An array storing prefix sums computed over numeric data elements
Explanation
The LCP array stores the length of the longest common prefix between consecutive suffixes in the suffix array, useful for many string problems.
Report an error in this question
String AlgorithmsHard
Q27. What is polynomial string hashing?
- A.Hashing using polynomial long division
- B.Computing hash as sum of characters times powers of a base✓ Correct
- C.Hashing that produces polynomial-length hash output
- D.Using polynomial time algorithms for hash computation
Explanation
Polynomial hashing computes hash(s) = s[0]×p^0 + s[1]×p^1 + ... + s[n-1]×p^(n-1) mod M, where p is a prime base. It supports efficient rolling hash computation.
Report an error in this question
String AlgorithmsHard
Q28. What is the longest repeated substring problem's optimal solution?
- A.O(n^3) brute force approach
- B.O(n^2) using dynamic programming
- C.O(n log^2 n) using rolling hashing
- D.O(n) using suffix array with LCP array✓ Correct
Explanation
The longest repeated substring can be found in O(n) time by building a suffix array and LCP array, then finding the maximum value in the LCP array.
Report an error in this question
String AlgorithmsHard
Q29. What is Manacher's algorithm?
- A.A string sorting algorithm for arrays
- B.A pattern matching algorithm for text
- C.A string compression algorithm for storage
- D.An O(n) algorithm finding all palindromic substrings✓ Correct
Explanation
Manacher's algorithm finds the longest palindromic substring (and all maximal palindromes) in O(n) time by cleverly reusing previously computed palindrome information.
Report an error in this question
String AlgorithmsHard
Q30. What is Burrows-Wheeler Transform (BWT)?
- A.A string matching algorithm for patterns
- B.A reversible transformation aiding text compression✓ Correct
- C.A string encryption method for security
- D.A hash function designed for string data
Explanation
BWT rearranges characters of a string by sorting all rotations, producing output with more character runs. It is reversible and used in bzip2 compression.
Report an error in this question