14.01.2011, 20:19, "Ian Kelly" <ian.g.ke...@gmail.com>:
> 2011/1/14 kost BebiX <k...@ya.ru>;:
>
>>  Well, isn't tree is a root node and it's children?
>
> And its grandchildren, great-grandchildren, etc.  What Alex is saying
> is that the implementation you posted traverses the root and its
> immediate children, but does not recur any further than that.  That is
> why it was so fast.

Oh, yeah, sorry, forgot the recursion. It should be (if I'm not wrong again):

    def post_order(self):
        for child in self.childs:
            for po in child.post_order():
                yield po
        yield self

if you give it more deepness:

$ python postorder.py 
building tree...done
0:00:25.839462
doing generator post_order...done
0:00:02.776876
doing non-generator post_order...done
0:00:01.092648

still not bad, but if you'll give it more deepness

$ python postorder.py 
building tree...done
0:00:16.078972
doing generator post_order...done
0:00:03.119023
doing non-generator post_order...done
0:00:00.841976

it will be worse

-- 
jabber: k...@ya.ru
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to