Strings Flashcards

(48 cards)

1
Q

What is a string?

A

A sequence of characters used to represent text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the time complexity of accessing a character in a string?

A

O(1), since strings are indexed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is string concatenation?

A

Combining two or more strings into one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the time complexity of string concatenation?

A

O(n + m), where n and m are the lengths of the strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a substring?

A

A contiguous sequence of characters within a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is string slicing?

A

Extracting a substring using index ranges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the time complexity of checking if a substring exists?

A

O(n) for brute force, O(n + m) using KMP.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the KMP algorithm?

A

An efficient string matching algorithm with O(n + m) time complexity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the Rabin-Karp algorithm?

A

A string matching algorithm using hashing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the Boyer-Moore algorithm?

A

A fast string matching algorithm that skips sections of the text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the time complexity of reversing a string?

A

O(n), where n is the length of the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a palindrome?

A

A string that reads the same forwards and backwards.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you check if a string is a palindrome?

A

Compare characters from both ends moving inward.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is string immutability?

A

Once created, a string cannot be changed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Are strings mutable in Python?

A

No, strings are immutable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you compare two strings?

A

Lexicographically, character by character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a character array?

A

An array of characters, often used to manipulate strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you find the longest common prefix?

A

Compare characters from the start of each string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the longest palindromic substring problem?

A

Finding the longest contiguous palindrome in a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the sliding window technique?

A

A method for tracking a subset of characters in a string during iteration.

21
Q

What is the two-pointer technique?

A

Using two indices to compare or manipulate parts of a string.

22
Q

What is the time complexity of finding all substrings?

23
Q

What is string hashing?

A

Converting a string into a numeric hash value.

24
Q

What is a rolling hash?

A

A hash function that updates efficiently when characters are added or removed.

25
What is the use of a trie with strings?
Efficient prefix-based operations like autocomplete.
26
How do you convert a string to lowercase or uppercase?
Use built-in functions like lower() or upper().
27
What is the difference between isalpha and isdigit?
isalpha checks for letters; isdigit checks for numeric digits.
28
What is string interpolation?
Inserting variables into a string using formatting.
29
What is an anagram?
Two strings that use the same characters in a different order.
30
How do you check if two strings are anagrams?
Sort both or use frequency maps.
31
What is the time complexity of sorting a string?
O(n log n)
32
What is the edit distance between two strings?
The minimum number of operations to convert one string into another.
33
What is the Levenshtein distance?
A type of edit distance allowing insert, delete, and replace.
34
What is dynamic programming used for in strings?
Solving problems like edit distance or longest common subsequence.
35
What is a suffix array?
An array of all suffixes of a string sorted lexicographically.
36
What is a longest common subsequence (LCS)?
The longest sequence that appears in both strings, not necessarily contiguously.
37
What is string compression?
Reducing the size of a string by encoding repeating patterns.
38
What is run-length encoding?
A basic compression method storing repeated characters as counts.
39
What is pattern matching?
Finding occurrences of a pattern within a string.
40
What is the time complexity of brute-force pattern matching?
O(n * m)
41
What is a Unicode string?
A string that supports a large set of characters from many languages.
42
What is ASCII?
A character encoding standard for English characters.
43
What is UTF-8?
A variable-width character encoding capable of encoding all Unicode characters.
44
What is string parsing?
Processing and analyzing the contents of a string.
45
What is a delimiter in a string?
A character or sequence that separates parts of the string.
46
What is the difference between split and join?
split divides a string; join combines list elements into a string.
47
What are escape characters?
Special characters used to represent things like newlines or tabs.
48
What is a null-terminated string?
A string that ends with a special null character '\0'.