Data structure (3) acwing
catalogue
1. Hash table
Hash function concept:
(1) X mod 10 ^ 5, that is, the value range {modulus is reduced. It is best to takePrime numberThe probability of collision is minimal}
(2) Conflict resolution
- Find the first greater than IQualitative factor
-
storage structure
-
open addressing
(the array length is 2 ~ 3 times) {operations involved: add, query and delete (just make a mark, not really delete)}
-
0x3f3f3f3f3f is a number greater than 10 ^ 9. In the memset() function, it is stored by bytes. Because h is an int array and occupies 4 bytes, it is enough to write a 0x3f (one byte is 0x3f)
-
-
Zipper method
-
-
String hash
- All string matching problems do not necessarily use KMP, but can also be usedString hashmode
- Usage scenario: compare whether two strings are equal
- KMP algorithm and string hash comparison: KMP is characterized by handling “circular knot”
The core is: take a string in k-ary form as a number
3.STL
1.vector
-
Size(), number of elements
-
Empty() returns whether it is empty
-
Clear
-
Front() / back() first / last element
-
push_ back() / pop_ Back() insert a number to the back / delete the last number of the array
-
Begin() / end() number 0 / number of the last numberLast number
Multiplication: when the system allocates space for a program, the time required is independent of the size of the space,Only related to the number of requests
2.string
- Size(), number of elements
- Empty() returns whether it is empty
- Clear
- Substr(): intercept string
- c_ Str(): the first subscript of the string
Initial subscript is 0
3.queue
-
empty()
-
size()
-
Push (): inserts an element at the end of the queue
-
Front(): returns the queue header element
-
Back(): returns the end of queue element
-
Pop (): pop up the queue header element
4.priority_ Queue (heap)
The default is large root heap, which is converted toSmall root pileThe way
- Push (): insert an element
- Top (): returns the heap top element
- Pop(): pop the top of heap element
5.stack
-
empty()
-
size()
-
push()
-
top()
-
pop()
6. Deque (double ended queue) — basically not use
Equivalent to enhanced vector
7.set、multiset、map、multimap
Size (), empty (), clear (), begin () / end () + +, – return the predecessor and successor, time complexity O (logn)
- set/multiset
- map/multimap
-
unordered_set,unordered_map,unordered_multiset,unordered_multimap
It is similar to the above, but the time complexity of adding, deleting, modifying and querying is O (1)
Lower is not supported_ bound() / upper_ Bound (), iterator + +–
-
BitSet pressure