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

Автор Aabhas99, история, 3 года назад, По-английски

If we know the number of entries beforehand, lets say v, then is it optimal to initialise the hashmap in java with size v or v/load_factor???

If we donot intialize it then it will be of size 16 and many times rehashing would be done.

So, on an average in contests what size should be chosen for optimal solution??

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

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

In my experience, it does not make a significant difference.

Perhaps it may be "optimal" but it likely won't be the difference between a TLE and AC.

Hope this helps.

Edit: Changed WA to TLE.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Why it would me Wrong answer, rather the chances are of tle when the solution is near the border of the time limit.

    There are some questions in which using array gives AC but using Hashmaps gives tle.My concern is for such type of questions!!