HomeSubjectsUniversityBlogAbout

Strings & Text Processing

Topic in Programming

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

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.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

Strings & Text ProcessingEasy

Q1. What does the length/len function return for a string?

  1. A.The index of the last character
  2. B.The memory size in bytes
  3. C.The number of characters in the string✓ Correct
  4. D.The ASCII value of the first character

Explanation

The length function returns the total number of characters in a string.

Report an error in this question

Strings & Text ProcessingEasy

Q2. How are strings typically stored in memory?

  1. A.As boolean value sequences
  2. B.As integer values in memory
  3. C.As an array of characters✓ Correct
  4. D.As floating-point numbers

Explanation

Strings are stored as sequences (arrays) of characters in memory.

Report an error in this question

Strings & Text ProcessingEasy

Q3. What is a substring?

  1. A.The name of a string variable only
  2. B.A string that contains no characters
  3. C.A contiguous portion of the string✓ Correct
  4. D.A complete copy of the entire string

Explanation

A substring is a contiguous sequence of characters within a string.

Report an error in this question

Strings & Text ProcessingEasy

Q4. What does the toUpperCase() method do?

  1. A.Converts all characters to lowercase
  2. B.Converts all characters to uppercase✓ Correct
  3. C.Reverses the character order fully
  4. D.Removes all whitespace characters

Explanation

toUpperCase() returns a new string with all alphabetic characters converted to uppercase.

Report an error in this question

Strings & Text ProcessingEasy

Q5. What is an empty string?

  1. A.A string with spaces only inside it
  2. B.An uninitialized variable with no type
  3. C.A null value with no reference set
  4. D.A string with zero characters in it✓ Correct

Explanation

An empty string is a string containing no characters, having a length of zero.

Report an error in this question

Strings & Text ProcessingEasy

Q6. What is string concatenation?

  1. A.Splitting a string into parts
  2. B.Reversing a string order
  3. C.Joining two or more strings✓ Correct
  4. D.Deleting a string entirely

Explanation

Concatenation combines two or more strings into a single string.

Report an error in this question

Strings & Text ProcessingEasy

Q7. What is the index of the first character in a string in most languages?

  1. A.-1
  2. B.2
  3. C.0✓ Correct
  4. D.1

Explanation

In most programming languages (C, Java, Python), string indexing starts at 0.

Report an error in this question

Strings & Text ProcessingMedium

Q8. What is a regular expression?

  1. A.A standard normal string literal value
  2. B.An algorithm for sorting string collections
  3. C.A pattern for matching and manipulating text✓ Correct
  4. D.A mathematical expression using operators

Explanation

A regular expression (regex) is a sequence of characters defining a search pattern for matching, finding, or replacing text.

Report an error in this question

Strings & Text ProcessingMedium

Q9. What is the difference between String, StringBuilder, and StringBuffer in Java?

  1. A.StringBuilder is immutable while String and StringBuffer are both mutable
  2. B.They are all identical in function and performance with no differences
  3. C.String is immutable; StringBuilder is mutable; StringBuffer is thread-safe✓ Correct
  4. D.StringBuffer is always the fastest option among all three implementations

Explanation

String is immutable. StringBuilder is mutable and fast but not thread-safe. StringBuffer is mutable and thread-safe but slower due to synchronization.

Report an error in this question

Strings & Text ProcessingMedium

Q10. What is the difference between mutable and immutable strings?

  1. A.Mutable strings always execute faster than immutable string types
  2. B.Immutable strings can dynamically grow in size without any limit
  3. C.There is no meaningful difference between the two string types
  4. D.Mutable strings can be modified in place; immutable ones cannot✓ Correct

Explanation

Mutable strings (e.g., StringBuilder) can be modified in place, while immutable strings (e.g., Java String) create a new object for any change.

Report an error in this question

Strings & Text ProcessingMedium

Q11. What is the String Pool in Java?

  1. A.A thread pool dedicated to string processing
  2. B.A mutable buffer for building string values
  3. C.A collection of string utility methods
  4. D.A heap area that caches string literals for reuse✓ Correct

Explanation

The String Pool is a special area in the Java heap that caches string literals, so identical string literals share the same reference.

Report an error in this question

Strings & Text ProcessingMedium

Q12. What does the split() method do?

  1. A.Divides a string into an array of parts✓ Correct
  2. B.Joins multiple strings into one
  3. C.Converts string to a character array
  4. D.Removes specified characters from string

Explanation

split() divides a string into an array of substrings using a specified delimiter or regular expression.

Report an error in this question

Strings & Text ProcessingEasy

Q13. What does the trim() method do?

  1. A.Removes leading and trailing whitespace✓ Correct
  2. B.Converts all characters to lowercase form
  3. C.Removes every character from the string
  4. D.Splits the string at every space character

Explanation

trim() removes whitespace characters from both the beginning and end of a string.

Report an error in this question

Strings & Text ProcessingEasy

Q14. How do you compare strings in Java?

  1. A.Using the == operator directly
  2. B.Using the + concatenation operator
  3. C.Using the > comparison operator
  4. D.Using the equals() method call✓ Correct

Explanation

In Java, equals() compares string content, while == compares object references.

Report an error in this question

Strings & Text ProcessingMedium

Q15. What is string interpolation?

  1. A.Converting strings to their numeric equivalents
  2. B.Splitting strings by a delimiter character
  3. C.Comparing two strings for equality or ordering
  4. D.Embedding variables directly within a string✓ Correct

Explanation

String interpolation allows embedding variable values or expressions directly in a string, e.g., f-strings in Python or template literals in JavaScript.

Report an error in this question

Strings & Text ProcessingEasy

Q16. What is a character in programming?

  1. A.A string of exactly two characters
  2. B.A numeric whole number data type
  3. C.A single symbol like a letter or digit✓ Correct
  4. D.A boolean true or false data value

Explanation

A character is a single symbol, typically represented by the char data type.

Report an error in this question

Strings & Text ProcessingMedium

Q17. What is Unicode?

  1. A.A type of data encryption algorithm
  2. B.An extension of the ASCII character set
  3. C.A universal character encoding standard✓ Correct
  4. D.A specific font type used in displays

Explanation

Unicode is a standard that assigns unique code points to characters from virtually all writing systems worldwide.

Report an error in this question

Strings & Text ProcessingHard

Q18. What is the KMP (Knuth-Morris-Pratt) string matching algorithm?

  1. A.A comparison-based sorting algorithm for arrays
  2. B.A tree traversal algorithm for binary search trees
  3. C.A linear-time string matcher using a failure function✓ Correct
  4. D.A hashing algorithm for generating unique hash codes

Explanation

KMP achieves O(n+m) string matching by precomputing a partial match table to skip unnecessary character comparisons.

Report an error in this question

Strings & Text ProcessingMedium

Q19. What is string encoding (like UTF-8)?

  1. A.Compressing a string to reduce storage size
  2. B.Encrypting a string for secure transmission
  3. C.Converting a string value into an integer
  4. D.Representing Unicode characters as byte sequences✓ Correct

Explanation

UTF-8 is a variable-length encoding that represents each Unicode code point as 1 to 4 bytes, backward-compatible with ASCII.

Report an error in this question

Strings & Text ProcessingHard

Q20. What is the time complexity of naive string matching?

  1. A.O(n*m)✓ Correct
  2. B.O(log n)
  3. C.O(n)
  4. D.O(n^2)

Explanation

Naive string matching compares the pattern at each position in the text, resulting in O(n*m) worst-case time complexity.

Report an error in this question

Strings & Text ProcessingMedium

Q21. What is the difference between ASCII and Unicode?

  1. A.ASCII supports many more characters than Unicode ever can
  2. B.Unicode is the older standard that was developed before ASCII
  3. C.They are exactly the same encoding standard with no differences
  4. D.ASCII uses 7 bits for 128 chars; Unicode supports over 143,000✓ Correct

Explanation

ASCII encodes 128 characters using 7 bits, while Unicode supports characters from all writing systems using variable-length encoding.

Report an error in this question

Strings & Text ProcessingMedium

Q22. What is a string builder pattern and when should you use it?

  1. A.A design pattern for constructing user interface strings
  2. B.A utility tool for building complex regular expressions
  3. C.A parser that transforms strings into structured data types
  4. D.Using a mutable class for efficient repeated concatenation✓ Correct

Explanation

When performing many string concatenations in a loop, StringBuilder is more efficient because it avoids creating many intermediate immutable string objects.

Report an error in this question

Strings & Text ProcessingHard

Q23. What is string interning?

  1. A.Compressing strings to reduce their memory size
  2. B.Storing one copy of each distinct string value✓ Correct
  3. C.Encrypting strings for secure data transmission
  4. D.Storing strings in a temporary memory buffer

Explanation

String interning stores a single copy of each unique string value, allowing equality checks via reference comparison instead of character comparison.

Report an error in this question

Strings & Text ProcessingHard

Q24. What is the Rabin-Karp algorithm?

  1. A.A graph traversal algorithm for shortest paths
  2. B.A string matcher using hashing for efficient search✓ Correct
  3. C.A comparison-based sorting algorithm for collections
  4. D.A compression algorithm for reducing data file sizes

Explanation

Rabin-Karp uses rolling hash functions to efficiently compare the pattern with substrings of the text, achieving O(n+m) expected time.

Report an error in this question

Strings & Text ProcessingHard

Q25. What is a rope data structure for strings?

  1. A.A contiguous array of individual character values
  2. B.A hash map that stores character frequency counts
  3. C.A singly linked list of character nodes
  4. D.A balanced tree for efficient long string operations✓ Correct

Explanation

A rope is a binary tree where leaves contain short strings, enabling efficient concatenation, insertion, and deletion on very long strings.

Report an error in this question

Strings & Text ProcessingHard

Q26. What is the Boyer-Moore string search algorithm's key insight?

  1. A.Start comparing from the beginning of the pattern each time
  2. B.Use hashing to compare the pattern against every position
  3. C.Compare every single character without skipping any at all
  4. D.Start from pattern end and use heuristics to skip sections✓ Correct

Explanation

Boyer-Moore compares the pattern from right to left and uses precomputed heuristics to skip large portions of the text.

Report an error in this question

Strings & Text ProcessingHard

Q27. What is the difference between UTF-8, UTF-16, and UTF-32?

  1. A.UTF-32 uses the least amount of storage space per character overall
  2. B.They are all identical encoding formats with no differences at all
  3. C.UTF-8 uses 1-4 bytes, UTF-16 uses 2-4 bytes, UTF-32 uses exactly 4✓ Correct
  4. D.UTF-8 is a fixed-width encoding that always uses exactly one byte

Explanation

UTF-8 uses 1-4 bytes (variable), UTF-16 uses 2 or 4 bytes, and UTF-32 uses exactly 4 bytes per character.

Report an error in this question

Strings & Text ProcessingHard

Q28. What are surrogate pairs in UTF-16?

  1. A.Duplicate characters stored in the encoding table
  2. B.Error codes returned by the UTF-16 encoding process
  3. C.Pairs of 16-bit units for characters beyond the BMP✓ Correct
  4. D.Paired delimiter characters used in string literals

Explanation

Characters with code points above U+FFFF require two 16-bit code units (a high surrogate and a low surrogate) in UTF-16 encoding.

Report an error in this question

Strings & Text ProcessingHard

Q29. What is a trie (prefix tree) and how does it relate to strings?

  1. A.A linked list that stores strings in sequential memory order
  2. B.A standard binary search tree data structure
  3. C.A hash table that maps string keys to their computed values
  4. D.A tree where each node represents a character for prefix search✓ Correct

Explanation

A trie stores strings character by character in a tree structure, enabling efficient prefix searches, autocomplete, and dictionary lookups.

Report an error in this question

Strings & Text ProcessingHard

Q30. What is the Levenshtein distance?

  1. A.The total length of a string in characters
  2. B.The count of matching characters between strings
  3. C.The byte size of a string in memory allocation
  4. D.The minimum single-character edits between strings✓ Correct

Explanation

Levenshtein distance measures the minimum number of edit operations needed to change one string into another, used in spell checking and fuzzy matching.

Report an error in this question

Ready to test yourself on Strings & Text Processing?

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