Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (anonymous):

It doesn't come up much in the class but does anyone know much about implementing a Tree Data Structure in python. I'd like to find a tutorial about how to do one to represent a family. Thanks.

OpenStudy (mattc):

I'm currently working on problem set 8, and in this problem set you have to use a binary tree. It uses recursion to transverse the tree and uses it to solve a Knapsack Problem. Might be helpful. Although I am having trouble with this problem set at the moment.

OpenStudy (anonymous):

Hey thanks for the reply. I have to do mine with OOP though like: class Node class Family etc.

OpenStudy (mattc):

have you worked with linked lists at all? I should be similar? except that it points too 2 places instead of 1

OpenStudy (anonymous):

My current implementation for the Node is: class Node(object): def __init__(self, name): self.name = name self.children = [] self.parent = None for item in relationdict: if relationdict[item] == self.name: self.children.append(item) relationdict is just a dictionary mapping sons to fathers This is working fine but when I try to extend it to make a family I keep failing.

OpenStudy (mattc):

I found an implementation of a binary tree, might help, http://code.activestate.com/recipes/286239-binary-ordered-tree/ unfortunately i do not know much about implementing a tree data structure or what you mean by a family.

OpenStudy (anonymous):

Sorry I meant Tree, the Tree is to represent a Family

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!