Terror_404's blog

By Terror_404, history, 2 months ago, In English

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.

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it +3 Vote: I do not like it

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.

»
2 months ago, # |
Rev. 3   Vote: I like it +10 Vote: I do not like it

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:
  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    great implementation

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Nice implementation

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.