Questions tagged [n-ary-tree]

31 questions
17
votes
2 answers

N-ary trees in C

Which would be a neat implemenation of a N-ary tree in C language? Particulary, I want to implement an n-ary tree, not self-ballancing, with an unbound number of children in each node, in which each node holds an already defined struct, like this…
mmutilva
  • 17,450
  • 21
  • 57
  • 80
6
votes
2 answers

Extracting Leaf paths from n-ary tree in F#

Inspired by this question, I wanted to try my hand at the latest ponder this challenge, using F# My approach is probably completely off course, but in the course of solving this problem, I'm trying to get a list of all the permutations of the digits…
Benjol
  • 57,639
  • 51
  • 180
  • 252
5
votes
1 answer

Drawing rooted trees with KineticJS

There's a webapp I'm developing that needs to draw rooted, n-ary trees dynamically, to map out the prerequisite relationships between skills. It actually already does this and you can see an example here. I'm trying to improve it though, using the…
Chris Fritz
  • 1,746
  • 1
  • 18
  • 23
4
votes
1 answer

N-ary tree depth and degree algorithm

I'm having some problems with a couple algorithms that should return the maximum degree (the max number of children of a node) and depth (dimension of the longest branch) of a tree. It looks like with some Tree structures they work, with some others…
Leo
  • 161
  • 1
  • 2
  • 11
3
votes
1 answer

Given a tree find the product of two values in the subtree rooted at a particular node such that the product has minimum number of zeros?

There will be q queries to the problem. In each query, you will be given a random node in the whole tree. Each node of the tree stores some integer value. The solver needs to give the minimum number of zeroes trailing the product of any two numbers…
3
votes
3 answers

The "Ruby" way of doing an n-ary tree

I'm writing a Ruby script and would like to use a n-ary tree data structure. Is there a good implementation that is available as source code? Thanks.
Bruno Antunes
  • 2,188
  • 4
  • 21
  • 32
3
votes
6 answers

F#: Recursive collect and filter over N-ary Tree

This is hurting my brain! I want to recurse over a tree structure and collect all instances that match some filter into one list. Here's a sample tree structure type Tree = | Node of int * Tree list Here's a test sample tree: let test = …
rysama
  • 1,652
  • 16
  • 26
3
votes
4 answers

Interview Questions - Serialize and deserialize n-ary tree

I recently faced this question during the interview and the interviewer asking me to create two function. Function1 should take the n-ary tree and convert to byte array and function2 should take the byte[] and build the n-ary tree. If it was a…
karthickeyan
  • 91
  • 1
  • 6
2
votes
1 answer

N-ary search tree in java with Comparable userObject?

So let's say I'm building a Tree using javax.swing.tree.DefaultMutableTreeNode and I add N children to a particular node. I want the children to be in a particular order (based on Comparable/a custom Comparator) like a search tree, even if I insert…
Seth
  • 5,156
  • 6
  • 38
  • 53
1
vote
3 answers

How to delete a nary tree ? each node has a parent pointer too in it

The structure of the node is below. struct node { int data; int noofchilds; node *child[n]; node *parent; }; I would appreciate both recursive and non-recursive approaches.
Peter
  • 2,609
  • 3
  • 22
  • 47
1
vote
3 answers

Number of distinct paths in tree, that have value of nodes in that path greater than or equal K

Problem Statement: You are given an integer N denoting number of nodes in that tree. Now, you need to count, how many distinct paths are there in the tree, such that, minimum node value in that path is greater than or equal to k. Input format: …
Deadpool
  • 2,198
  • 9
  • 22
1
vote
1 answer

Traverse n-Ary tree Level Order

Let the structure given by: // Struct to nAry tree struct nNode { int val; // Some value (in future use a pointer to some data) struct nNode *next; // Siblings of the same parent if next == NULL is the last struct nNode…
Lin
  • 966
  • 6
  • 20
1
vote
1 answer

Breadth-First N-ary tree traversal

I'm coding up an N-ary tree representation of file system hierarchies, which contains some information about the directories/files. Each node in the tree consists of a parent node, and a list of its children (if any) and is contained within a…
Richardweber32
  • 148
  • 1
  • 14
1
vote
0 answers

Creating N-ary tree in java with a linked list structure

I have to create an nary tree using a linked list. I have already implemented a nary tree, but not sure how to go about changing it to a linked list structure. Please help. public class NaryTree extends AbstractTree { protected Object key; …
PaliKid
  • 11
  • 1
1
vote
1 answer

Can't wrap my head around populating an n-ary tree

I am working on a homework project where I read a list of connecting stations from a file and create a hashmap in the format (key = String station, value = ArrayList connecting stations) so far so good. The user can then select a home station at…
Astabh
  • 59
  • 2
  • 11
1
2 3