8.1 --- string data structure

(A) string

 

1, substring: sequences of any consecutive string of characters called a sub-string of the string
Note: the empty string belongs substring

2, character strings are not identical: n string consisting of characters, assume each character is different, asked how many substrings

Answer: n-(n-+. 1) / 2 +. 1

Tip: The individual characters are not the same
analysis:
sub-string of characters comprises a total of n number of
sub-character string comprising two co the n-1
contains three characters common substrings two n-2
comprises four sub-character total n-3 series th
......
sub-string containing n characters of 1
empty string a
sum: total number of sub-strings: 1 + 2 + 3 +. . . + n + 1 (the empty string) = n (n + 1) / 2 + 1
Example application: If the string S = 'software', the number of which is a substring ()

Analytical: n (n + 1) / 2 + 1 = 8 (8 + 1) / 2 + 1 = 37

3, character string duplicates: all non-empty string www.qq.com strings (two strings based on a count only if the contents are the same) number is ()

Answer: 50

Note: presence of the same characters, calculated as the total number of repetition subtracted number, i.e. n (n + 1) / 2 + 1- repeat number

Analysis: comprising repeating substring Total: n (n + 1) / 2 + 1 = 10 (10 + 1) / 2 + 1 = 55, minus the repetition: 2 w, 1 th ww, 1 th q, 1 th ., so that a total of 55-5 = 50

 

Questions:

  in-place standing: itself O (1 space); recursion, stack space may not be considered

  Issues related to the place: a string rotate left and right movement

  Sliding window: to achieve complexity of O (n) time; complexity of O (1) space

  Related rules

  Match (violence): KMP

  Manacher: linear time seeking palindromic substring

 

(B) algorithm

First, the dictionary order

 

Second, the operation is simple: insert, delete characters, rotation

1. The copy and character replacement

 

2. Flip word

 

Third, the rule judgment (the Roman numeral converter, is a valid integer, floating point)

Fourth, the digital arithmetic (addition of large numbers, binary addition)

 

Fifth, sorting, exchange (partition process)

1.0-1 exchange

Question: put a 0-1 string sorting, you can swap any two locations, and asked the least number of exchanges?

 

2. exchange asterisk

1 idea: fast row partition, will change the numerical order

Ideas 2: backwards copy, in numerical order will not change

 

 

 

 

Six Character Count (hash): anagram

Seven, matching (regular expressions, the whole string matching, the KMP, determination period)

Eight, dynamic programming (LCS, edit distance, the longest palindrome substring)

IX search (word conversion, permutations)

 

Ten, sliding window

1. substring anagram

Ideas 1: hash

 

 

 

references:

[1] [Google] algorithms Ali interview succinctly _ beep beep miles miles (゜-゜) zu ro Cheers ~ -bilibili

[2] Solving the number of strings contained substring

Guess you like

Origin www.cnblogs.com/nxf-rabbit75/p/11815062.html