Please can anyone provide a good implementation of trie using a 2D array instead of using recursion ?

# | User | Rating |
---|---|---|

1 | tourist | 3557 |

2 | Um_nik | 3494 |

3 | Radewoosh | 3344 |

4 | wxhtxdy | 3309 |

5 | LHiC | 3302 |

6 | Benq | 3286 |

7 | mnbvmar | 3274 |

8 | Petr | 3254 |

9 | yutaka1999 | 3190 |

10 | ksun48 | 3170 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 191 |

2 | Radewoosh | 180 |

3 | PikMike | 165 |

3 | antontrygubO_o | 165 |

3 | Vovuh | 165 |

6 | tourist | 161 |

7 | rng_58 | 160 |

8 | majk | 156 |

8 | Um_nik | 156 |

10 | 300iq | 155 |

Please can anyone provide a good implementation of trie using a 2D array instead of using recursion ?

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/16/2019 06:31:28 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

let f be the matrix representation of your trie

let f[k] be the list of links for the k-th node

let f[k][x] = m, the node who represents the son of k-th node using x-th character, m = -1 is there is not a link.

Notes: Root node is at f[0] sz is the numbers of nodes currently in trie

I guess would be easy to you implement other functions.

can you explain it by taking an example?

It is an explanation where you are storing the size of the trie ..But it is not suitable when we need to use this for finding the prefixes or calculating the xor or something like that ...Is it ???

How to mark a complete word? Using another array of same size of f? If we can't mark complete word, incomplete word will be found by searching.

It's my implementation of trie without using recursion and with using 2D array.

Nice code!! Thanks a lot.. Helped a lot

chrome Can you please explain your code. It would be really nice and helpful.

Thanks chrome!

thanks,,can you plz add a delete operation?

You can find it in PrinceOfPersia's blog on data structures.

My code here

I like this because 'add' and 'query' are in the same function (: