kuroko's blog

By kuroko, 11 years ago, In English

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?

  • Vote: I like it
  • +5
  • Vote: I do not like it

| Write comment?
»
11 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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 years ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

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

»
11 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
11 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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