Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 surveying the Monastery: (10)
As of 2014-10-01 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (38 votes), past polls