Q1. How are strings typically stored in memory?
- A.As boolean value sequences
- B.As integer values in memory
- C.As an array of characters✓ Correct
- D.As floating-point numbers
Explanation
Strings are stored as sequences (arrays) of characters in memory.
Topic in Programming
A string is a sequence of characters stored as text, and string processing covers creating, searching, comparing and transforming that text in a program. Questions examine how strings sit in memory, including null-terminated C strings, immutability in Java and Python, and the ASCII versus Unicode and UTF-8 encoding distinction. Common operations include concatenation, substring, split, contains, case conversion, interpolation and equals versus == comparison. Expect string interning, StringBuilder for efficient building, and Unicode normalisation pitfalls. Algorithm questions compare naive matching with KMP, which uses a prefix table, the Z-algorithm, Rabin-Karp hashing and Aho-Corasick for matching many patterns at once.
Below are 30 practice questions from a pool of 210 Strings & Text Processing MCQs, one of 16 topics in Programming. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.
Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
Q1. How are strings typically stored in memory?
Strings are stored as sequences (arrays) of characters in memory.
Q2. What does the length/len function return for a string?
The length function returns the total number of characters in a string.
Q3. What is string concatenation?
Concatenation combines two or more strings into a single string.
Q4. What is the index of the first character in a string in most languages?
In most programming languages (C, Java, Python), string indexing starts at 0.
Q5. What does the toUpperCase() method do?
toUpperCase() returns a new string with all alphabetic characters converted to uppercase.
Q6. What is a substring?
A substring is a contiguous sequence of characters within a string.
Q7. What is an empty string?
An empty string is a string containing no characters, having a length of zero.
Q8. What does the trim() method do?
trim() removes whitespace characters from both the beginning and end of a string.
Q9. How do you compare strings in Java?
In Java, equals() compares string content, while == compares object references.
Q10. What is a character in programming?
A character is a single symbol, typically represented by the char data type.
Q11. What is the difference between mutable and immutable strings?
Mutable strings (e.g., StringBuilder) can be modified in place, while immutable strings (e.g., Java String) create a new object for any change.
Q12. What is a regular expression?
A regular expression (regex) is a sequence of characters defining a search pattern for matching, finding, or replacing text.
Q13. What is string interpolation?
String interpolation allows embedding variable values or expressions directly in a string, e.g., f-strings in Python or template literals in JavaScript.
Q14. What is the String Pool in Java?
The String Pool is a special area in the Java heap that caches string literals, so identical string literals share the same reference.
Q15. What is the difference between String, StringBuilder, and StringBuffer in Java?
String is immutable. StringBuilder is mutable and fast but not thread-safe. StringBuffer is mutable and thread-safe but slower due to synchronization.
Q16. What does the split() method do?
split() divides a string into an array of substrings using a specified delimiter or regular expression.
Q17. What is Unicode?
Unicode is a standard that assigns unique code points to characters from virtually all writing systems worldwide.
Q18. What is the difference between ASCII and Unicode?
ASCII encodes 128 characters using 7 bits, while Unicode supports characters from all writing systems using variable-length encoding.
Q19. What is string encoding (like UTF-8)?
UTF-8 is a variable-length encoding that represents each Unicode code point as 1 to 4 bytes, backward-compatible with ASCII.
Q20. What is a string builder pattern and when should you use it?
When performing many string concatenations in a loop, StringBuilder is more efficient because it avoids creating many intermediate immutable string objects.
Q21. What is the time complexity of naive string matching?
Naive string matching compares the pattern at each position in the text, resulting in O(n*m) worst-case time complexity.
Q22. What is the KMP (Knuth-Morris-Pratt) string matching algorithm?
KMP achieves O(n+m) string matching by precomputing a partial match table to skip unnecessary character comparisons.
Q23. What is string interning?
String interning stores a single copy of each unique string value, allowing equality checks via reference comparison instead of character comparison.
Q24. What is the Rabin-Karp algorithm?
Rabin-Karp uses rolling hash functions to efficiently compare the pattern with substrings of the text, achieving O(n+m) expected time.
Q25. What is a trie (prefix tree) and how does it relate to strings?
A trie stores strings character by character in a tree structure, enabling efficient prefix searches, autocomplete, and dictionary lookups.
Q26. What is the difference between UTF-8, UTF-16, and UTF-32?
UTF-8 uses 1-4 bytes (variable), UTF-16 uses 2 or 4 bytes, and UTF-32 uses exactly 4 bytes per character.
Q27. What is a rope data structure for strings?
A rope is a binary tree where leaves contain short strings, enabling efficient concatenation, insertion, and deletion on very long strings.
Q28. What is the Levenshtein distance?
Levenshtein distance measures the minimum number of edit operations needed to change one string into another, used in spell checking and fuzzy matching.
Q29. What is the Boyer-Moore string search algorithm's key insight?
Boyer-Moore compares the pattern from right to left and uses precomputed heuristics to skip large portions of the text.
Q30. What are surrogate pairs in UTF-16?
Characters with code points above U+FFFF require two 16-bit code units (a high surrogate and a low surrogate) in UTF-16 encoding.
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.
Start Strings & Text Processing Quiz