Closed Thread
Results 1 to 6 of 6

Thread: Binary Tree with linked lists help

  1. #1
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Binary Tree with linked lists help

    Okay so right now I have a program that is running. It makes a tree and each tree has a linked list attached to it.
    The tree is somewhat binary but in a hierarchy form so its not in the correct number order. Basically each node is referred to as a "costcenter" and each costcenter has a linked list which are expenses which has a name and an amount.
    It puts the tree and linked list together right now but im brainstorming on the second output. It outputs one just by adding all expenses up in the list and displaying it by the node - if the nodes is under another node the node above it gets the amount as well. There are lots of ways of doing the second output but im trying to find one where its fast and doesn't require much I was thinking somewhat recursive... either way whats your opinion on the fastest way to do this one? It may require a list just because its in a hierarchy form.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    ReignInChaos's Avatar
    ReignInChaos is offline Learning Programmer
    Join Date
    Feb 2009
    Location
    NJ
    Posts
    46
    Blog Entries
    5
    Rep Power
    12

    Re: Binary Tree with linked lists help

    If you need to traverse all the parent nodes or simply all the nodes in general, a recursive traversal would be the best route for you to take. I am a little unclear exactly what it is that you are trying to do so if you need more help please explain a little more.

  4. #3
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Binary Tree with linked lists help

    Yes I need to transverse all the nodes but then each node of the binary tree had a linked list and I needed to be able to add all the amounts in the linked list to get the total for each node but then each node also counts for all nodes under it.

    I actually figured it out - I might post the code in a bit in the other forum a bit later.

  5. #4
    micheljaw is offline Newbie
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Re: Binary Tree with linked lists help

    This depends on several things, of course. I'd say that a linked list is right out, since it has few suitable properties to work as a symbol table. A binary tree might work, if you already have one and don't have to spend time writing and debugging it. My choice would be a hash table, I think that is more or less the default for this purpose.
    -----------------------------------------------

  6. #5
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Binary Tree with linked lists help

    Well a hash table wouldnt work well - all the names are in number format - that is the names of the costcenters and the names of the expenses so id have to mod the number and those are really easily going to overlap.

    My binary tree and linked list solution did work - I ended up keeping a few more variables (time vs space) to make it run faster. It keeps an end total of how much the node has "spent" and all the parent nodes also get a copy of the expense.

    I posted the source of this up a few days ago if you guys want to see...

    View Source Code here - CodeCall

  7. #6
    Join Date
    Jan 2008
    Posts
    1,725
    Blog Entries
    4
    Rep Power
    29

    Re: Binary Tree with linked lists help

    For what you are doing (if I understand it correctly), I would almost made a node class that holds onto the individual values in a list. Then have it hold onto a total sum and have a sum option in it to grab the sum of all the values in that list and update the main sum. This way, you don't end up with a larger runtime than what is required, especially in this tree which will already run in log time for a single lookup.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Linked Lists
    By chili5 in forum Java Tutorials
    Replies: 2
    Last Post: 09-01-2009, 02:10 PM
  2. Intermediate Linked Lists
    By WingedPanther in forum C Tutorials
    Replies: 5
    Last Post: 12-30-2008, 09:34 AM
  3. Linked Lists
    By Andrew.Anderson.2008 in forum C and C++
    Replies: 1
    Last Post: 06-27-2008, 09:39 AM
  4. questions about linked lists
    By jkurth in forum Java Help
    Replies: 0
    Last Post: 11-10-2007, 04:33 PM
  5. Linked lists of strings (C)
    By Panserbjorn in forum C and C++
    Replies: 1
    Last Post: 10-26-2007, 02:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts