Strings Flashcards
(48 cards)
What is a string?
A sequence of characters used to represent text.
What is the time complexity of accessing a character in a string?
O(1), since strings are indexed.
What is string concatenation?
Combining two or more strings into one.
What is the time complexity of string concatenation?
O(n + m), where n and m are the lengths of the strings.
What is a substring?
A contiguous sequence of characters within a string.
What is string slicing?
Extracting a substring using index ranges.
What is the time complexity of checking if a substring exists?
O(n) for brute force, O(n + m) using KMP.
What is the KMP algorithm?
An efficient string matching algorithm with O(n + m) time complexity.
What is the Rabin-Karp algorithm?
A string matching algorithm using hashing.
What is the Boyer-Moore algorithm?
A fast string matching algorithm that skips sections of the text.
What is the time complexity of reversing a string?
O(n), where n is the length of the string.
What is a palindrome?
A string that reads the same forwards and backwards.
How do you check if a string is a palindrome?
Compare characters from both ends moving inward.
What is string immutability?
Once created, a string cannot be changed.
Are strings mutable in Python?
No, strings are immutable.
How do you compare two strings?
Lexicographically, character by character.
What is a character array?
An array of characters, often used to manipulate strings.
How do you find the longest common prefix?
Compare characters from the start of each string.
What is the longest palindromic substring problem?
Finding the longest contiguous palindrome in a string.
What is the sliding window technique?
A method for tracking a subset of characters in a string during iteration.
What is the two-pointer technique?
Using two indices to compare or manipulate parts of a string.
What is the time complexity of finding all substrings?
O(n^2)
What is string hashing?
Converting a string into a numeric hash value.
What is a rolling hash?
A hash function that updates efficiently when characters are added or removed.