Common interview summary

topK problem

If you need to get the largest K values, you can build a small heap. Otherwise, build a large pile.

  • First read the first K data into a minimum heap
  • Then traverse the subsequent data, and for each traversed data, compare with the top element of the heap (the smallest comparison among the K data). If it is smaller than the top data of the heap, continue to traverse the subsequent data. If it is larger than the top element of the heap, delete the top element of the heap and store the currently traversed data, and the entire data process until all the data is traversed.
    TOPK problem

vector expansion

VS is 1.5 times expansion, because Linux needs to be compatible with the partner algorithm of memory management, 2 times expansion is adopted. How to use vector efficiently and avoid expansion as much as possible? If you know the number of data to be stored in the vector in advance, you can use the reserve(n) function to avoid the inefficiency caused by multiple expansions.
Constant expansion, the average complexity of inserting each element is O(N)
multiple expansions, and the average insertion complexity of each element is O(1)
vector expansion

If there are 4 billion QQ, how to store

Here, our storage purpose is mainly for query, so we can use bitmap to store binary information about the existence of a certain QQ. About 500M space is consumed.
Mass storage

Talk about multi-process and multi-thread

Talk about the advantages and disadvantages of multithreading and multiprocessing

TCP's three-way handshake and four waved hands

TCP connection establishment and closing

Guess you like

Origin blog.csdn.net/qq_35353824/article/details/108059353