Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Least common ancestor function implemented in perl

by vikramkone
on Nov 29, 2007 at 02:33 UTC ( #653749=perlquestion: print w/ replies, xml ) Need Help??
vikramkone has asked for the wisdom of the Perl Monks concerning the following question:

Hi. This is a problem of the infamous LCA in binary trees..! I heard that this can be easily implemented in perl using a CPAN module called "bioperl". I have never used it ..so have no idea. if any one knows , or used it before..if they can write a small program for the below program..it would be great. Thanks -------------------------------------------------------------- Problem: Write a class for a "Doubly-Linked" Tree; child nodes have links to their parents and vice versa (whatever the proper term is for such a tree). This tree can be a binary tree, for simplicity, and should only have one root node. Using the above class, write a subroutine, common_parent(node1, node2), which return the first parent node that the two nodes have in common.

Comment on Least common ancestor function implemented in perl
Re: Least common ancestor function implemented in perl (Homework)
by erroneousBollock (Curate) on Nov 29, 2007 at 02:44 UTC
    Your protestations in a previous thread notwithstanding, this is clearly homework. What gave you away? Err, how about quoting the question verbatim (necessarily in a writing style differing from your own).

    If you're doing homework, we'd love to see what you've tried already. I suspect you've made no good-faith attempt at all. It's simply unfair to palm your work off onto PM (where someone will eventually give you an answer).

    Whether your 'homework' is for a high school, college/university, or a self-study program... the same considerations apply to effort and pay-off in the long run.

    Ethically, I also believe you should put "Homework: " in the title and <blockquote></blockquote> the question to clearly denote the text as having been written by another... (if for no ethical reason) to satisfy copyright fair-use exemptions.

    -David

Re: Least common ancestor function implemented in perl
by dragonchild (Archbishop) on Nov 29, 2007 at 03:23 UTC
    Of course, you could just look on CPAN and find Tree which will get you about 2/3's of the way there.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Least common ancestor function implemented in perl
by roboticus (Canon) on Nov 29, 2007 at 11:10 UTC
    vikramkone:

    While it may be able to be solved by one of the bioperl modules, the problem requests that you write the doubly-linked tree class to solve the problem. What've you tried thus far? Post some code and I'll be happy to give some feedback.

    ...roboticus

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://653749]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (18)
As of 2014-07-10 14:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (212 votes), past polls