Triangle Calc: Parent Index to Child Indexes

In summary, the conversation discusses a function that takes the index of a parent element in a flattened triangle and returns a tuple containing the indexes of its children. The formula for finding the index of the first element in the nth row is also mentioned.
  • #1
DavidSnider
Gold Member
511
146
Let's say you have a triangle like:
1
2 3
4 5 6
7 8 9 10

The children of each element in the triangle are those directly adjacent on the next row. For example the children of 4 are 7 and 8. The children of 5 are 8 and 9.

Now let's say we flatten it to: [1,2,3,4,5,6,7,8,9,10]

Is there a way to compose a function that takes the index of the parent and returns a tuple containing the indexes of the children? (Assume 0 based indexes. The 1 through 10 are values, not indexes)
 
Last edited:
Mathematics news on Phys.org
  • #2
Is 7 a child of 5?
 
  • #3
No.

1: 2,3
2: 4,5
3: 5,6
4: 7,8
5: 8,9
6: 9,10

It's easier to picture when you draw the triangle as a pyramid shape, but I couldn't get the forum to format it that way.
 
  • #4
Hi DavidSnider! :smile:

Use the CODE tag :wink:
Code:
          1
         2 3
        4 5 6
       7 8 9 10

Hint: the kth element in the nth row is parent to the kth and k+1th elements in the n+1th row, and the index of the first element in the nth row is … ? :smile:
 
  • #5
Ah, thanks. I think I got it.

First element in nth row is the same as the triangle number:
[tex]\frac{n^2 + n}{2}[/tex]

What I needed was the Triangle root:
[tex]\frac{-1\pm\sqrt{8n+1}}{2}[/tex]

so the index would be:
[tex]n+\frac{1+\sqrt{8n + 1}}{2}[/tex]
 
Last edited:

What is "Triangle Calc: Parent Index to Child Indexes"?

"Triangle Calc: Parent Index to Child Indexes" is a mathematical formula used to determine the relationship between the parent index and the child indexes in a triangle. It is often used in computer science and data structures.

How is the parent index defined in "Triangle Calc: Parent Index to Child Indexes"?

The parent index is the index of a node in a tree or data structure that is connected to its child nodes. In a triangle, the parent index is the index of the parent triangle, which is used to calculate the indexes of the child triangles.

What are the child indexes in "Triangle Calc: Parent Index to Child Indexes"?

The child indexes are the indexes of the smaller triangles that make up the larger parent triangle. They are calculated using the parent index and the specific formula for "Triangle Calc: Parent Index to Child Indexes".

Why is "Triangle Calc: Parent Index to Child Indexes" important in computer science?

This formula is important because it allows for efficient navigation and manipulation of data structures, specifically in tree-like structures. It helps to determine the relationships between parent and child nodes, which can be useful in various algorithms and programming tasks.

Can "Triangle Calc: Parent Index to Child Indexes" be applied to other shapes or structures?

Yes, the concept of parent and child indexes can be applied to other shapes and structures, such as squares, hexagons, and even graphs. However, the specific formula for "Triangle Calc: Parent Index to Child Indexes" may not be applicable and would need to be adjusted for the specific shape or structure being used.

Similar threads

  • General Math
Replies
24
Views
2K
  • General Math
Replies
4
Views
1K
  • General Math
Replies
2
Views
5K
  • Programming and Computer Science
Replies
27
Views
2K
Replies
2
Views
3K
  • General Math
Replies
4
Views
728
  • Set Theory, Logic, Probability, Statistics
Replies
12
Views
1K
  • General Math
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
2K
Back
Top