1

I have a tree-like structure. I can get several lines that connect together and make up the tree. The lines are made up start-points and end-points. here is some sample data from a tree in XML format.

<Skeleton>
   <Line StartX="384" StartY="135"  EndX="385" EndY="129"  /> 
   <Line StartX="384" StartY="137"  EndX="384" EndY="135"  /> 
   <Line StartX="384" StartY="138"  EndX="384" EndY="137"  /> 
   <Line StartX="384" StartY="139"  EndX="384" EndY="138"  /> 
   <Line StartX="383" StartY="144"  EndX="384" EndY="139"  /> 
   <Line StartX="383" StartY="147"  EndX="383" EndY="144"  /> 
    ...
</Skeleton>

and here is a graphical representation of the tree:

enter image description here

What I need to do is to extract the leafs and the junctions on this tree as it is shown in the image: enter image description here

I want to find an optimized algorithm regarding complexity and time to do this task.

mahsa.teimourikia
  • 1,664
  • 9
  • 32
  • 64
  • possible duplicate of [Looking for algorithm: skeleton generation for raster images](http://stackoverflow.com/questions/18060540/looking-for-algorithm-skeleton-generation-for-raster-images) – amit Aug 06 '13 at 08:52
  • 1
    No, it's not a duplicate, that post wants to get the skeleton out of an image. different stuff! – mahsa.teimourikia Aug 06 '13 at 09:20

1 Answers1

3
  1. Generate a mathematical graph out of your data (coordinates are the labels of the vertices and each line from your data becomes an edge in the graph).

  2. define the root vertex of your tree.

  3. leafs are all vertices that are not the root vertex and connected to only one edge

  4. junctions are all vertices that are connected to at least 3 edges (in your example)
MrSmith42
  • 9,961
  • 6
  • 38
  • 49
  • 1
    Thanks for the suggestion. therefore, after having the graph, I can use some search algorithms to find the leafs. – mahsa.teimourikia Aug 06 '13 at 09:23
  • Why not simply create a tree and do level order traversal and traverse all nodes except root node? Why take complicated root of graph(Though tree is also a graph) – AKS Aug 07 '13 at 09:28
  • @AKS: As you mentioned yourself _'tree is also a graph'_. I cannot see, why you think using a graph is more complicated than using a tree. By the way, how would you create the tree while parsing the XML? While parsing the XML the already parsed will most likely not be a tree most of the times, because we cannot make any assumptions about the order of the lines in the XML. – MrSmith42 Aug 08 '13 at 06:37