Questions tagged [multiway-tree]

A multiway tree is a tree where each node can have a variable number of children.

A tree data structure is a structure consisting of nodes with some number of children. Many trees a binary trees (each node has 0, 1, or 2 children), though trees with multiple children exist as well. This tag is appropriate for questions specifically about multiway trees.

52 questions
1
vote
1 answer

How to tree traversal a multiway tree

I have tried to traverse a multiway tree, but I'm trying to do in an efficient way but that doesn't really help me and more importantly I want to do it recursively. My idea was like this: I have a tree, a child and it's siblings. I want to go…
J. Homer
  • 147
  • 1
  • 11
1
vote
1 answer

flatten a tree with a list of subtrees in Haskell

I would like to flatten a tree which looks like this: > data Tree a = Leaf a > | Fork a [Tree a] > | Root [Tree a] possible example: Root [Fork 'a' [Fork 'b' [Leaf 'c'],Fork 'c' [Leaf 'b']],Fork 'b' [Fork 'a' [Leaf…
homior
  • 161
  • 1
  • 12
1
vote
1 answer

How to generate graphically tree with parent and child based on n level from database using array in PHP?

I have following kind of data to table: id    parent_id    child_id    level 1     53987          52548       1 2     60764          52548       2 3     60764          53987       1 4     …
1
vote
2 answers

Multiway trees and structures

I have a problem in applied math that can be almost perfectly mapped to finding the longest path in a multiway tree. I have a function child() which gives child nodes (points in space satisfying a condition). The only caveat is that child() requires…
Bari Tala
  • 37
  • 8
1
vote
1 answer

multiway tree memory allocation of children

I am trying to build a multi-way tree in C. I've got stuck on allocation memory for childrens. I have a vector which contains the fathers of each node. Here is my code: #define MAX_CHILDS 10 int t[10] = {1, 2, 4, 1, -1, 3, 2, 1, 0, 4}; NODE…
smotru
  • 433
  • 2
  • 8
  • 24
1
vote
3 answers

PROLOG (How to postorder a multiway tree )

I'm struggling with a Prolog homework like below, Prolog uses general trees, not binary trees. An example is a(b,c,d(e,f,g)) where root a has 3 kids, as does kid d. It is possible to define both preorder and postorder for general trees,…
1
vote
3 answers

check if a child is a descendant using a single mysql query

Suppose I have this table parent | child 1 2 1 3 2 4 4 5 5 6 and I want to check if 6 is a descendant of 1 (which it is)....can I accomplish this within one…
pillarOfLight
  • 8,592
  • 15
  • 60
  • 90
1
vote
2 answers

Multiway tree comparable interface issue

I am creating a generic multiway tree which I KNOW will take only one of four types (Integer, Double, String and Character). I am having problems with the comparable interface and my insert function. Here is the relevant code I have written so…
Tim
  • 73
  • 1
  • 2
  • 11
0
votes
1 answer

Diameter of an N-ary Tree represented as a Binary Tree

I need to compute the diameter of an N-ary tree represented as a Binary Tree (left-child, right-sibling representation). Can someone give me an idea or a pseudocode? My best attempt was to add a +1 to the result whenever there was a left child, but…
0
votes
1 answer

how to know if the given multiway tree is the sub structure of another multiway tree

Given a big multiway tree A and a small multiway tree B, how can we know if B is a sub-structue of A?
irasin
  • 145
  • 6
0
votes
0 answers

When I add a node to the array of sons of another parent node of a multiway binary tree, error "segmentation fault" appears

I'm trying to create a multiway binary tree from a parent array. The structure for my multiway binary tree nodes is the following: typedef struct x{ int id; struct x* son[MAX]; int index; }nodeR2; I use this function to allocate memory…
0
votes
1 answer

2,4 tree with the fewest number of nodes with the given keys

suppose we have a set of keys K = {1, 2, 3, 4, 5, 6,..., 15} and we need to build a two four tree out of this such that: CASE1 : the tree has the minimum number of nodes. CASE2 : the tree has the maximum number of nodes. my idea - a node in the…
0
votes
1 answer

Finding the height of a multiway (general tree) using OCaml

As a newbie in functional programming (OCaml), I stuck with that problem. I came up with a code shown below: let rec height tr = match tr with | Node(d,[]) -> 1 | Node(d,[t1]) -> 1 + height t1 | Node(d,[t1;t2]) -> 1 + max (height t1) (height…
eznora
  • 15
  • 4
0
votes
1 answer

Enumerate all paths through a rose tree Haskell

I'm working with a version of a Tree of the type: Tree = Empty | Leaf Event | Split String [(String, Tree)] My aim is to get a function that returns a list of pairs [(Event,[Int])] with [Int] being the coordinates (the path taken in the tree to…
0
votes
1 answer

How to split node when inserting in 2-3-4 Tree?

Is there a rule for how to split the node in 2-3-4 tree? E.g. If I insert 3, 7, 4, 9 into the 2-3-4 tree: Will it be split like this (yellow) or that (green) as shown here: Are both valid?
user963241
  • 6,758
  • 19
  • 65
  • 93