Блог пользователя kuroko

Автор kuroko, 11 лет назад, По-английски

In cases where we need to store 10^7 or more integers what is the best method for storing and accessing these data.Vector is one of the solution but is that the fastest because when we access by index ([]) I read there are some overhead. So is there any better method?

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think it is depedent of problem,cause in some cases you dont need array for some implementations. Some cases for problems would be the "string" or "map" in c++.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

It would help it you could explain the use case that you are trying to solve. 10 pow (7) roughly requires 24 bits, so you can use 3 bytes instead of 4 to save them. The problem with using vectors is that they need to be resized, amortized complexity of insertion is still constant.

definition of vector.at()

So technically once you already have a vector at() should have no overhead (except for the range check)

»
11 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

O(blog(n)) sorting will be slow for n = 107 . Sorry its O(nlogn)

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

unorderer_map — это лучше вектора _)

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Array.More about it you can find here http://www.cplusplus.com/doc/tutorial/arrays/.