Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How can I code this?

  1. Jul 21, 2008 #1
    I have the following problem:

    Suppose I have a tree of data as follows (Labels represent the branches of the tree, Nodes represent data "leaves" contained in the branches):

    Label1
    Node1
    Node2
    Label2
    Node3
    Label3
    Node4
    Node5
    Label4
    Node6

    I want to move every "label" or "branch" of the tree that contains only one "node" or "leaf" into the highest level of the tree and delete that branch. I basically want to remove the branches that contain one leaf and move the data from that leaf into the highest level of the tree. So for the example I have, I would like it to become the following:

    Label1
    Node1
    Node2
    Node3
    Node6
    Label3
    Node4
    Node5

    What is the best way to code such a problem, and would any one language be suitable for this task? The data I have is in an excel file so I suppose I could do it in there but I'm looking for a more elegant way to do it, preferably in Python/Perl/Java/MATLAB. Thanks!
     
  2. jcsd
  3. Jul 21, 2008 #2

    zyh

    User Avatar

    i't very hard to understand your question, So , I draw two pictures to demostrate your question.

    The original tree is like this:
    [​IMG]

    After moving the single node to the first level and delete the related nodes.
    [​IMG]

    I think it's very easy to do with some algorithms in " data structure" but, if you are manipulating Excel File, it's better to use Matlab...
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: How can I code this?
  1. How i can learn ? (Replies: 16)

Loading...