3

It has a single root and each node has 0..N ordered sub-nodes . The keys represent a distinct set of paths. Two trees can only be merged if they share a common root. It needs to support, at minimum: insert, merge, enumerate paths.

For this tree:

The
 +--------+----------------+
 |        |                |
cat      cow              dog
 +        +--------+       +
 |        |        |       |
drinks   jumps    moos    barks
 +
 |
milk

the paths would be:

  • The cat drinks milk
  • The cow jumps
  • The cow moos
  • The dog barks

It's a bit like a trie. What is it?

Christophe
  • 81,699
Daniel
  • 699

3 Answers3

5

By Wikipedia, it looks like your tree is specified by the two properties arborescence and ordered tree (scroll down to find the definition "ordered tree or plane tree.")

Sonia
  • 231
  • 1
  • 3
3

This is very close to a Radix tree. The primary differences are that a normal radix tree wouldn't split on words, so the 'c' in both "cat" and "cow" would be the same node, and it only splits when necessary:

The
 +-------------------------+
 |                         |
 c                        dog barks
 +---------------+                 
 |               |                 
at drinks milk   ow               
                 +--------+        
                 |        |        
                jumps    moos         

I might describe what you have as a modified Radix tree, that is forced to use spaces as a delimiter. Regardless, it is some sort of "tree", so that should be sufficient to describe it if you have some extra explanation as to its structure.

Izkata
  • 6,118
  • 7
  • 30
  • 44
0

This is called a "rope" when applied specifically to strings, I believe.

http://en.wikipedia.org/wiki/Rope_(computer_science)

They offer vastly improved algorithmic complexity for many mutating operations over strings-as-arrays.

Robert Harvey
  • 200,592
DeadMG
  • 36,914