int arr[10]; // you have O(n) linear algorithm for search
但是当你使用:
std::vector<int> V;
的问题是:什么是算法的复杂搜索矢量的impelentation的背后?
int arr[10]; // you have O(n) linear algorithm for search
但是当你使用:
std::vector<int> V;
的问题是:什么是算法的复杂搜索矢量的impelentation的背后?
在搜索中的阵列和std::vector
是O(n)
不O(log n)
O(log n)
将只有当阵列/ std::vector
排序来实现。
std::vector
实现不包含任何搜索算法,但要获得O(log n)
您首先需要对它进行排序然后执行二分搜索,这与数组也是一样的。
@MohsenPahlevanzadeh我不认为我需要更新我的文章,恕我直言,你几乎已经改变了你现在的整个问题,无论如何,在'std :: vector'中执行搜索,你可以使用[_'std :: find'_](http://en.cppreference .COM/W/CPP /算法/找到) – P0W
'std :: vector'具有恒定的随机存取时间,所以它是一样的。 – kec
可能重复[std :: vector与std :: array在C++](http://stackoverflow.com/questions/4424579/stdvector-versus-stdarray-in-c) – Dinal24