AlgorithmOne of the frequently asked questions is searching or sorting. I personally feel that 80% of the questions are related to searching and sorting.
The time complexity of most common sorting algorithms is O (nlogn)
This can only be a general solution.
This requires a low level of time complexity in algorithm interview questions,
For example
It is known that the length of an array is m and the value range is 1-M. The elements in the middle may be repeated or not repeated.
How can I find out which of the (1-m) numbers are repeated and which do not appear in the O (m) case?
The essence of counting sort is to create an array with a length of M. An array subscript represents a number, and the value in the array represents the number of times this element appears (the initial value is 0)
Then, when m is traversed at a time, A number is added to the corresponding subscript by 1.
In the end, we can obtain the number of occurrences of an containing all elements.
Expand it to obtain the sorted array.
This is a special algorithm that can only solve special problems, but its time complexity is O (n)
If you encounter sorting or searching algorithms, try counting sort first.