1. : What is the time complexity of searching for a substring in a string using the Knuth-Morris-Pratt algorithm?
(A) O(n)
(B) O(m + n)
(C) O(n²)
(D) O(m)
2. : Which of the following algorithms is used for pattern matching in strings?
(A) Quick Sort
(B) Merge Sort
(C) Rabin-Karp Algorithm
(D) Dijkstra’s Algorithm
3. : What is the primary use of the Levenshtein distance algorithm?
(A) To find the shortest path in a graph
(B) To measure the similarity between two strings
(C) To sort strings alphabetically
(D) To concatenate strings
4. : Which algorithm is commonly used for finding the longest common subsequence?
(A) Dynamic Programming
(B) Greedy Algorithm
(C) Divide and Conquer
(D) Backtracking
5. : What does the Boyer-Moore algorithm primarily optimize?
(A) Memory usage
(B) Pattern matching efficiency
(C) String sorting
(D) Substring searching
6. : In which scenario is the Rabin-Karp algorithm most efficient?
(A) When searching for a single character
(B) When the pattern is long and there are many patterns
(C) When searching for patterns in sorted strings
(D) When using a small alphabet
7. : What is the primary advantage of using tries for string storage?
(A) Fast substring searching
(B) Efficient memory usage
(C) Fast insertion and deletion operations
(D) Easy to implement
8. : Which of the following is NOT a string manipulation operation?
(A) Concatenation
(B) Insertion
(C) Sorting
(D) Compiling
9. : What does the term ‘string hashing’ refer to?
(A) Converting a string into a numerical value
(B) Breaking a string into characters
(C) Sorting a string alphabetically
(D) Finding the length of a string
10. : Which algorithm is used to find the longest palindromic substring?
(A) Manacher’s Algorithm
(B) KMP Algorithm
(C) Rabin-Karp Algorithm
(D) Aho-Corasick Algorithm
11. : What is the worst-case time complexity of the naive substring search algorithm?
(A) O(n)
(B) O(m + n)
(C) O(n²)
(D) O(m²)
12. : What does the ‘replace’ operation in string manipulation do?
(A) Deletes a substring
(B) Replaces occurrences of a substring with another substring
(C) Splits a string into an array
(D) Appends characters to a string
13. : Which method is used to convert a string to lowercase in many programming languages?
(A) lower()
(B) toLowerCase()
(C) convertToLower()
(D) makeLower()
14. : What is a common application of the Z algorithm?
(A) Sorting strings
(B) Pattern matching
(C) String comparison
(D) String reversal
15. : What does the ‘split’ operation do in string manipulation?
(A) Merges two strings
(B) Divides a string into substrings based on a delimiter
(C) Removes characters from a string
(D) Appends characters to a string
16. : Which string manipulation algorithm uses a sliding window technique?
(A) Rabin-Karp
(B) KMP
(C) Longest Common Substring
(D) Longest Palindromic Substring
17. : What is the purpose of the ‘trim’ operation in string manipulation?
(A) To sort a string
(B) To remove leading and trailing whitespace
(C) To find the length of a string
(D) To convert a string to uppercase
18. : Which of the following is a property of immutable strings?
(A) Strings can be modified after creation
(B) Memory is reused
(C) Strings cannot be changed once created
(D) Strings are stored in a heap
19. : What does the ‘substring’ operation do?
(A) Returns the entire string
(B) Creates a new string from a portion of the original string
(C) Deletes a portion of the string
(D) Sorts the characters in the string
20. : Which algorithm is used to compare two strings for equality?
(A) Boyer-Moore
(B) Knuth-Morris-Pratt
(C) Simple comparison
(D) Z Algorithm
21. : What is a common application of string manipulation algorithms in natural language processing?
(A) Text classification
(B) Image processing
(C) Video analysis
(D) Data compression
22. : Which data structure is commonly used to implement a trie?
(A) Array
(B) Linked List
(C) Tree
(D) Hash Table
23. : What is the purpose of a suffix tree?
(A) To store only unique substrings
(B) To provide fast substring searching
(C) To compress strings
(D) To sort strings
24. : What is the time complexity of the Boyer-Moore algorithm in the average case?
(A) O(m + n)
(B) O(n)
(C) O(n²)
(D) O(m)
25. : Which of the following is a greedy algorithm for string manipulation?
(A) Huffman Coding
(B) Dynamic Programming
(C) Binary Search
(D) Merge Sort
26. : What is the purpose of using character encoding in strings?
(A) To compress strings
(B) To convert strings into numerical values
(C) To represent characters in bytes
(D) To sort strings
27. : Which operation can be performed to check if a string is a palindrome?
(A) Reverse the string and compare
(B) Count the characters
(C) Sort the string
(D) Remove whitespace
28. : What is the main advantage of using string interning?
(A) Reduces memory usage
(B) Increases performance
(C) Simplifies string operations
(D) Allows for easy comparison
29. : Which of the following methods would you use to join an array of strings?
(A) concatenate()
(B) join()
(C) merge()
(D) append()
30. : What is the main difference between shallow and deep copying of strings?
(A) Shallow copies the data, deep copies references
(B) Shallow copies references, deep copies the data
(C) There is no difference
(D) Shallow copying is faster
31. : In which application are string manipulation algorithms often used?
(A) Image processing
(B) Web scraping
(C) Sorting numbers
(D) Graph algorithms
32. : What is the time complexity of the naive algorithm for finding all occurrences of a substring?
(A) O(n)
(B) O(m + n)
(C) O(n²)
(D) O(m²)
33. : What is the output of the ‘reverse’ operation on the string “hello”?
(A) “olleh”
(B) “hello”
(C) “he”
(D) “world”
34. : Which algorithm is used for compressing strings?
(A) Run-Length Encoding
(B) Merge Sort
(C) Dijkstra’s Algorithm
(D) Bubble Sort
35. : What does a regular expression do in string manipulation?
(A) Sorts strings
(B) Searches and manipulates text based on patterns
(C) Converts strings to numbers
(D) Formats strings
36. : What is the main purpose of the Knuth-Morris-Pratt algorithm?
(A) To sort strings
(B) To find the longest common substring
(C) To efficiently search for substrings
(D) To remove duplicates from strings