tags:

views:

165

answers:

10

I'm wondering if there's an existing word to describe a process that I'm currently using. I want to call it "flattening a tree" but I feel like there must be a better word or phrase.

input:

  |--D
--B
| |--C
|
A-E
|
| |--G
--F
  |--H

output:

[ [A, B, D]
  [A, B, C]
  [A, E]
  [A, F, G]
  [A, F, H] ]

Is there an established name for this process?

A: 

You need a depth first search to capture every path from the root to a leaf.

Pseudo code:

global allPaths = []
R = root
currentPath = []
findPaths(R, currentPath)

findPaths(R, currentPath){
if R has no children,
allPaths.add( currentPath )

else
for each child C in R:
findPaths(C, currentPath + R)
}
Stefan Kendall
Yes, but is there a word for a function that returns an array of paths? There very well may not be.
mwhite
You're "finding all paths to leaves". I don't think you can get a single word for it.
Stefan Kendall
Pathlist. Bam! Single word.
JavadocMD
It is not a pathlist. It is a list of paths from the *root only*
Stefan Kendall
Rootedpathlist. I can do this all day. :)
JavadocMD
...to the leaves.
Stefan Kendall
+3  A: 

I'd say you're just traversing the tree, while keeping a path to the current node. As you visit a leaf, you print the complete path to the leaf.

I don't think there's a specific name, but it is not much different from a very simple traversal.

Steven Schlansker
+1  A: 

How about 'Hydrating' (or DeHydrating) depending on the situation ?

SoftwareGeek
I'm not sure a textbook would list that, but +1 for the actual submission of a 'name' :-)
pst
@pst - much appreciated!!
SoftwareGeek
apparently some coward has downvoted. what a nite!
SoftwareGeek
+1  A: 

De-Normalisation would seem to be best. Because indeed, if you notice your new structure you have redundant data, and it would appear to map directly to the conceptual idea.

Noon Silk
+2  A: 

How about "Chainsawing"

WOPR
+2  A: 

Path enumeration?

DFS traversal?

or my favourite

Tree arrayfication!

Blakomen
It does look like an enumeration of all the paths so 'path enumeration' would seem to fit.
Hightechrider
A: 

I think of it as coalescing portions of the tree.

Andy Dent
A: 

Yes, it is called Serializing

Scott
A: 

If the input is the tree and the output is the list of lists you quote, you are not actually looking for a phrase for the process, you're looking for a name for the subroutine you call. And the name of such a subroutine should be a description of what it returns.

How about RootPathsOfLeaves ? or some rearrangement thereof...

AakashM
A: 

Tree / Node Serialization?

James McCormack