Results 1 to 4 of 4

Thread: How To Evenly Distribute Elements In A Tree

  1. #1
    Join Date
    Nov 2011
    Posts
    2

    How To Evenly Distribute Elements In A Tree

    HI GUYS
    am new to this forum and please bear with me if my questions have been tackled before or seems silly.

    i need some help on the following

    i need to evenly distribute elements into ab-tree like tree but with many nodes say (n). there is one root node and i will call it 0. then root nodes have say 10 child nodes and each child node have the same number of child nodes up to a certain level say 4.

    what i want is distribute numbers into it evenly e.g if the tree have 100 nodes and i have 100 numbers 1 to 100 each node must have a number in it.

    can there be an algorithm or equation that can return me the specific node that a certain number must be stored or a way of numbering each node so that number 1 will sit in node 1 , number 15 will sit in node 15 and so on.

    thanks in advance.

  2. #2
    Join Date
    Jun 2006
    Posts
    623

    Re: How To Evenly Distribute Elements In A Tree

    Check the below algorithm example that will evenly distribute 1 to many items into three columns which is in Python:

    Code:
    NumCols = 3
    DATA = "ABCDEFGHIJK"
    
    for ItemCount in range(1, 12):
        subdata = DATA[:ItemCount]
    
        Col1Count = (ItemCount + NumCols - 1) / NumCols
        Col2Count = (ItemCount + NumCols - 2) / NumCols
        Col3Count = (ItemCount + NumCols - 3) / NumCols
    
        Col1 = subdata[:Col1Count]
        Col2 = subdata[Col1Count:Col1Count+Col2Count]
        Col3 = subdata[Col1Count+Col2Count:]
    
        print "%2d   %5s  %5s  %5s" % (ItemCount, Col1, Col2, Col3)
    
    # Prints:
    #  1       A              
    #  2       A      B       
    #  3       A      B      C
    #  4      AB      C      D
    #  5      AB     CD      E
    #  6      AB     CD     EF
    #  7     ABC     DE     FG
    #  8     ABC    DEF     GH
    #  9     ABC    DEF    GHI
    # 10    ABCD    EFG    HIJ
    # 11    ABCD   EFGH    IJK

  3. #3
    Join Date
    Nov 2011
    Posts
    2

    Re: How To Evenly Distribute Elements In A Tree

    thanks Gusgr8

    I am not sure if the piece of code will be able to distribute the elements if there are sub nodes. this is because from i have seen from the code it is distributing elements in 3 containers on the same level. What i am looking for is distribute elements in a tree with many levels.

    suppose i have a tree that have a root node. that root node have 3 child nodes. each child node have 3 child nodes and so on say up to level 4. if i number each node from the root node and numbering from left to right, the root node being number 1 and the left child of the root being number 2, the middle child of the root being number 3 and the right being number 3. on the third level the left child node of the left child node of the root being number 5 and so on. if i have numbers 1 up to 13 and want to put each number into a node numbered the same i.e number 1 gets into the root node, number 2 gets into the left child node of the root and so on. how would i achieve that.
    its like i am looking for a way of getting the vector location of each node.

    i will attach a diagram of the tree.
    thanks
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2006
    Posts
    605

    Re: How To Evenly Distribute Elements In A Tree

    I think that if you have N elements indexed from 0 to N-1 and column indexed from 0to 2, the i-th element will go in column i mod 3 (where mod is the modulo operator, % in C,C++ and some other languages).

Similar Threads

  1. VBScript to split a text file evenly in three
    By Kazz013 in forum Software Development
    Replies: 3
    Last Post: 16-12-2010, 06:35 PM
  2. Replies: 8
    Last Post: 02-01-2010, 05:53 AM
  3. Atari to Publish and Distribute Ghostbusters
    By kex in forum Video Games
    Replies: 1
    Last Post: 07-11-2008, 01:28 PM
  4. How to distribute PPS to customers on CD?
    By Marry in forum Windows Software
    Replies: 2
    Last Post: 08-09-2008, 12:34 PM
  5. Photoshop Elements and Premiere Elements go to version 7.0
    By Killen in forum Customize Desktop
    Replies: 2
    Last Post: 29-08-2008, 01:17 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
  •  
Page generated in 1,713,987,096.72328 seconds with 17 queries