# Count-Min Sketch (Continue...)


![left](./student-guide/diagram/18-Count-Min-Sketch-02-01.png)

------------------------------------------------------------
1. Data structure purpose: to count the frequency of elements in a real-time data stream, and to answer the frequency of an element in real time, unneeded accurate results.

2. Basic ideas:
Create an array of length x to count, initialize the count value of each element to 0;
For a new element, hash to a number between 0 and x, such as the hash value i, as the position index of the array;
This is the count value of the position index i corresponding to the array plus 1;

3. How to use:
Then, to query the frequency of occurrence of an element, simply return the count value of the position index of the array corresponding to the element ha hope.

4. Optimized:
Considering the use of hashes, there will be conflicts (hash collisions), where different elements are hashed to the same array position index, so the frequency statistics will be too large. So we need to do the following optimizations:
Use multiple arrays and multiple hash function to calculate the position index of an array corresponding to an element;
Then, when querying the frequency of an element, you can return the minimum value of the element's count values in different arrays.
