52 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
93
views
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 ...
0
votes
1
answer
16
views
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?
0
votes
0
answers
45
views
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;
}...
0
votes
1
answer
737
views
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 ...
2
votes
2
answers
151
views
Decoding a recursive multiway tree
I'm working on a recursive tree of this type
type Node anyType
= Leaf Id (Maybe anyType) Name
| Tree Id (List (Node anyType)) Name
where
type Id
= Id Int
| Root
and I'm trying to decode a ...
1
vote
1
answer
172
views
Elm - fold on recursive type with list does not compile
I'm following this article on catamorphism and I'm trying to define a fold function for a recursive data type like this
type Node anyType
= Leaf Id (Maybe anyType)
| Tree Id (List (Node ...
0
votes
1
answer
813
views
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 ...
-2
votes
1
answer
350
views
Finding the number of the neighbours of a given node of a multiway tree (rose tree) in Haskell
Consider the following definition of a Rose Tree:
The tree can contains unique nodes.
data NTree a = Nil | Node { root :: a, subtree :: [NTree a]} deriving Show
-- or just data NTree a = Nil | Node a [...
6
votes
3
answers
853
views
Progressively store the path from root node to node of multiway tree during insertion so that the storage operation does not have a complexity of O(n)
I would like to ask if someone knows a performant way to store the path from the root node to a new node of a multiway tree during the insertion of the new node. E.g., if I have the following tree:
...
3
votes
2
answers
482
views
How to memoize the repeated subtrees of a game tree (a potentially infinite rose tree)?
I am attempting to implement the Negamax algorithm in Haskell.
For this, I am representing the future possibilities a game might take in a rose tree (Data.Tree.Forest (depth, move, position)). ...
1
vote
2
answers
462
views
Print tree node and all of it's childs efficiently
I am trying to make a function that would print a node and all of its children but I am trying to make it efficient and also recursive. But it doesn't really work.
#include <stdio.h>
#include &...
1
vote
1
answer
784
views
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 ...
0
votes
1
answer
492
views
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 ...
1
vote
1
answer
661
views
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' [...
1
vote
1
answer
390
views
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 ...