algorithm - To check whether a tree is binary or not -


given (n-ary) tree. how check whether binary or not?

how check whether binary or not?

check if every node has @ 2 children.

some untested (!) pseudo-code:

struct ntree {    root: node    boolean isbinary() {     return isbinary(root)   }    private boolean isbinary(node n) {     if (n has no child)       return true     elif (n has 1 child)       return isbinary(n.children[0])     elif (n has 2 children)       return isbinary(n.children[0]) && isbinary(n.children[1])     else       return false   }    struct node {     children: list   } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -