Fastest way to search and sort vectors

前端 未结 6 1476
甜味超标
甜味超标 2021-01-02 18:16

I\'m doing a project in which i need to insert data into vectors sort it and search it ...

i need fastest possible algorithms for sort and search ... i\'ve been sea

6条回答
  •  甜味超标
    2021-01-02 18:55

    Sorting

    In case you want to know about the fastest sorting technique for integer values in a vector then I would suggest you to refer the following link: https://github.com/fenilgmehta/Fastest-Integer-Sort

    It uses radix sort and counting sort for large arrays and merge sort along with insertion sort for small arrays. According to statistics, this sorting algorithm is way faster than C++ std::sort for integral values.

    It is 6 times faster than C++ STL std::sort for "int64_t array[10000000]"

    Searching

    If you want to know whether a particular value is present in the vector or not, then you should use binary_search(...)

    If you want to know the exact location of an element, then use lower_bound(...) and upper_bound(...)

提交回复
热议问题