A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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.

  • This Question is Closed
  1. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  3. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  5. mattc
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.