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

Автор netflix, история, 6 лет назад, По-английски

Whenever I solve a question using the Keyword Tree / Trie data-structure, I implement it using pointers. But I have seen many programmers implementing trie using arrays.

What are the downsides of using the Pointers implementation (if at all) , as compared to the Arrays implementation ?

Pointers Implementation Code

Arrays Implementation Code

Happy Coding !

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

»
6 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Pointers dynamically allocate memory which takes a bit more time. In array implementation you already have a fixed size declared- this saves time. So you see there is a trade-off between time and memory. Both are equally efficient under normal circumstances. Only when the constraints are too tight you may need to choose between the two.