You are not logged in.
Pages: 1
Hi,
I am a programmer developing an application that will create a number of of objects in a hierarchial format. I have 2 variables available to the user. "Number of objects/items per branch" and "How many levels deep" So if 2,2 is selected the end result would be similar to this.
#
#
#
#
#
#
if 3,3 is selected the a result would look like this
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
Obviously increasing either of these numbers will cause the hierarchy(total amount of objects) to increase at an exponential rate can anyone suggest a method of calculating the total number of objects that would be created from a the 2 variables.
Thanks you,
Brendan Fafiani
Let's take a look at what those results actually are.
In your first example, you have a total of 2 objects in the first level (Because that's what your first number specified), then 4 objects in the next, because each of those 2 objects has 2 objects coming off it and it stops there because you specified that it has 2 levels.
So overall, you have 2 + 2² = 6 objects.
In the 2nd example, you have 3 objects in the first level, then 3² in the next and 3³ in the third, and then it stops because you specify it has 3 levels.
So, that's 3 + 3² + 3³ = 39 objects.
Generally, the formula for the amount of objects (if n is the amount of objects and L is the amount of levels) would be n + n² + n³ + ... + n[sup]L[/sup].
That formula is perfectly valid, but it's a bit messy for high values of L, so it's much easier to simplify it down to this:
With your two examples, this formula would do this:
Why did the vector cross the road?
It wanted to be normal.
Offline
the sum of geometric progression (a = objects, b = levels)
so lets test it out
you could also write it
ah blasted, mathsyperson beat me to it, stupid breakfast
Last edited by luca-deltodesco (2006-08-22 22:41:22)
The Beginning Of All Things To End.
The End Of All Things To Come.
Offline
Sweet! Thanks you very much. Your reply rings a bell back to my college days.
Regards,
Brendan Fafiani.
Pages: 1