Tag Archives: tree

Prefix Tree

Creating a prefix tree is quite easy in Python! root = {} def addToTree(node, word=()): if not word: return addToTree(node.setdefault(word[0], {}), word[1: ]) def main(): for word in (‘batman’, ‘bane’, ‘bale’,): addToTree(root, word) print root Output: {‘b’: { ‘a’: { ‘l’: { ‘e’: {} }, ‘n’: { ‘e’: {} }, ‘t’: { ‘m’: { ‘a’: […]

0  

N-dimensional aka N-ary Tree

N-dimensional tree is used to represent the UI of any application. Buttons, ComboBoxes and various other components are assembled together in this data structure and then rendered on the screen. I had to enhance the design of a commercial Tree UI component (add improved searching features) and thought of creating my own n-ary Tree data […]

1