Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

Can Anybody give me the sample code of implementation of basic trie using multidimensional arrays. I saw various programmers using this. And i personally feel i will be a lot more comfortable in handling arrays than using node pointers in tries.

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

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

Auto comment: topic has been updated by Terror_404 (previous revision, new revision, compare).

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

Auto comment: topic has been updated by Terror_404 (previous revision, new revision, compare).

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

can't it be implemented using an adjacency list? I don't remember exactly as I learnt it a long time ago but any information will be appreciated.

»
6 месяцев назад, # |
Rev. 3   Проголосовать: нравится +10 Проголосовать: не нравится

Here is a simple implementation problem and a solution with an array-based trie to this problem. The code should hopefully be clear enough for you to figure out what's happening.

Statement:
Example:
Code:
  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    great implementation

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

    Nice implementation

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

    Since all 26 'branches' are hardly used, it may be worth considering using a dynamically allocated array or set for the second dimension that holds the paths within the trie to save memory. $$$log\ 26$$$ or $$$log\ |branches|$$$ is constant, so this optimization will have no asymptotical difference.