I have an arraylist which is linked in a tree structure (a family tree to be precise). Each node is an object containing a generation field. I would like to find the leaf with the highest generation within the tree. I tried this:

```
private int findHighestLeafGeneration(FamilyMember node, int gen){
if(node.getChildren().isEmpty()){
return gen;
}
for(int i = 0; i < node.getChildren().size(); i++){
gen = findHighestLeafGeneration(node.getChild(i), node.getChild(i).getGeneration());
}
return gen;
}
```

I call the method like this:

```
findHighestLeafGeneration(node, node.getGeneration());
```

What this is supposed to do is take a member of the family tree (a node) and print all the descendants for that member. My PrintDescendants method requires the number of generations to print.

The above is a little buggy however. It gets the leaf generation then returns and overwrites the leafs generation with the parent nodes generation. Any clues why?

Do this:

```
private int findHighestLeafGeneration(FamilyMember node) {
int gen = node.getGeneration();
for(int i = 0; i < node.getChildren().size(); i++){
int highestChild = findHighestLeafGeneration(node.getChild(i));
if(highestChild > gen) {
gen = highestChild;
}
}
return gen;
}
```

Similar Questions

I'm trying to write a function that returns the smallest value in the binary tree not a binary search tree. Here's what I've written, it's not correct. def min(root, min_t): # min_t is the initially t

How do I design a query with mongoose/mongodb to search within a date range and extract the highest price values for each day within that range? Right now, the only way I know how to do this is to exe

I have to find certain highest value in an array(for example fifth highest value). I wrote an alogithm but it takes too long. Any ideas how to make it faster? int tab[100]; // cin tab; int position;

i have a mysql table i.e st_id | name | email | maths | chemistry | bio | social_study 1 | john |@a.com | 20 | 23 | 10 | 15 my question is how can i find the highest subject score, the second last

I need to write a function that takes a list as a parameter and find the second highest value in the list. Return that value. If there is only one value in the list, return that value. If the list is

What is the best way to store n-ary tree (ex: directory hierarchy) in JavaScript ? I need to have following operations on it: 1. add 2. delete 3 update Is there any JavaScript library which provide th

I found that Eric Lippert's post here suits a particular problem I have. The problem is I can't wrap my head around how I should be using it with a 2+ amount of collections. Having var collections = n

I have an Array that I need to transform it to an N-ary tree. I know the value of N, and the total number of nodes. I give you an example in the picture below. The N-ary tree should be ordered as ill

i have a sql table: C1 | C2 | C3 aa | bb | 21 gg | hh | 53 dd | yy | 37 I want the the top 5000 rows with highest value in C3 but I want my data to be ordered by C1 How can I do this? Thanks.

Say I have a multi dimensional array like the following: [ [.1, .2, .9], [.3, .4, .5], [.2, .4, .8] ] What would be the best* way to return a single dimension array that contains the highest value fr

I have a tree of depth k and branching factor of n. I've been trying to find a general formula for: Maximum number of nodes possible in this tree Minimum number of nodes possible in this tree Any su

I am trying to identify if a value is repeated sequentially in a vector N times. The challenge I am facing is that it could be repeated sequentially N times several times within the vector. The purpos

I am using a d_ary_heap_indirect as a priority queue (to process items with the highest priority first) using a property map to store the priorities. However, when I change the values in the priority

I came across this proposition that a binary tree with n! leaves has height omega(n log n). I am unable to understand how it is possible. I understand that height of a binary tree with n nodes is log

Why is the worst case big-O for inserting N items into an empty binary search tree n^2? there are no balance checks.

I'm trying to have female animal agents select all patches that have no females within a certain radius. Then, from among those patches, I'd like the female to move to the one which has the highest av

I have a n-level checkbox tree implemented using knockout, where selection of a parent level chechbox should select its children (but not the other way around) and once data is submitted the ids of el

I insert elements to the DOM, after that I want to bind a click function to these elements. This works, but for some reason the links that were created all return the same value, which is the highest

I have a table of employees and salaries defined that way: name (type: VARCHAR) salary (type: INTEGER) What query can I use to get the second highest salary in this table?

I'm trying to get the Body Mass Index (BMI) classification for a BMI value that falls within a standard BMI range - for instance, if someone's BMI were 26.2, they'd be in the Overweight range. I mad

I've a task to write a function with type ‘a btree -> ‘a option list that stores the given tree in a list of elements of type ‘a option in postfix order (postorder). Internal nodes will be represen

How can I do to get the element with the attribut name equal to 'temp' and with the highest attribut value? XML <el> <em name=temp value=5> <data>nok</data> </em> <

I'm trying to implement an optimal game of checkers in C. In order to find the optimal move of the checker board that can be made by the machine, I have generated a n-ary game tree using (GLib) in C b

I would like to fetch the highest value (from the column named value) for the 7 past days. I have tried with this sql: SELECT MAX(value) as value_of_week FROM events WHERE event_date > UNIX_TIMESTA

I'm trying to get a mapping function like this working for an n-ary tree, but am struggling. data NTree a = Leaf a | Node a [NTree a] ntreeMap :: (a -> b) -> NTree a -> NTree b ntreeMap f (Le

(In case you want to avoid the lengthy explanation, all I am looking for is a level order traversal for a generic-tree(n-ary tree) in java. The code supplied works and needs the level order display fu

Recently I was asked to write some code to find the highest n elements in a list and return both the values and the locations. Can you get any quicker (in terms of execution time) than this? def high

I'm creating Binary Search Tree class I got all my functions working accept the Successor. My tree input is 30 10 45 38 20 50 25 33 8 12 When I print Inorder traversal it come up as 8 10 12 20 25 30

I want to search an array for duplicate values in each subarray and if there is one, only keep the highest value connected to this item. That's my question, but I love to add an example to clarify thi

I am new in Haskell. I trying to learn implementation of N-ary trees in Haskell. I tried to construct N-ary tree and so I create my own data type data Tree = Empty | Node Integer [Tree] deriving Show

I have HashSet which contain list of objects as Student and professor and department. It needs to check which student have the highest marks and professor which have student with highest marks in tota

I have the following input where a user watched a program in the following percentages (25 or 50 or 75 or 100).I just want to calculate the highest percentage viewed by a certain user on a certain id.

I have a code like this. My intended result is to grab the highest value from a set range of timestamps. I'm not sure why this isn't working. I am using Oracles SQL 10. Thank you in advance for your h

hi i have this code to search a n-ary tree but it dosent works correctly and i dont know whats wrong with that when searching n4 and n5 it return n3 whats wrong? public FamilyNode findNodeByName(Fami

I have info in a database which can have different versions per entity. I want to retrieve the highest entity I want to get the highest version from the column Version. Now I'm doing this like this: l

I use sed to get the content of file from a desire point but I have a problem. I can not print $variable value into this sed command count=$(sed -n '/$variable/,$p' file.log | grep 'KO' -c) I try w

I'm trying to implement an N-ary Tree in c++ using the glib, but as I'm not a c++ expert, I'm having some problems finding out how to use it right. Does anybody have a simple example written in C++ to

How do I retrieve the second highest value from a table?

I'm writing a method which determines the highest value in a .NET enumeration so I can create a BitArray with one bit for each enum value: pressedKeys = new BitArray(highestValueInEnum<Keys>());

I am using recursive method to create a Binary Search Tree. My objective is to find the lowest element in the tree. Below is my code. Insertion node insert(node root, int value) { if ( root == NULL )

I am trying to figure out a function f(x) that would calculate the number of leaves in a k-ary tree. For example, assume we created a tree that began with root 4 with 3 children, each of -1,-2,-3 resp

We have N integer counters, initially showing 0. Operations: int getMax() - returns the highest value shown by counters. void increment(int i) - increments value of counter i. void zero() - set zero v

I am watching a lecture on threading and they use the term m-ary vector as follows: Let [X] represent an m-ary vector of non-negative integers What is this? Is the arity the length? I presume a vec

I've a question, how can I get the highest value, then the lowest value, then the second highest value from a table. For example: in the table Name Value ---------------------- Apple 2 Pear 3 Pineappl

I need help to get the highest and lowest value in an array. I saw some people use Math.max and Math.min but how do you apply it? in this code? import java.util.Scanner; public class CaseStudy2A { pub

For example, if I have an list of objects with the following properties No Grouper Sorter 1 X 3 2 X 2 3 X 1 4 Y 3 5 Y 2 6 Y 5 7 Z 4 I want the result to contain object no 3 (X with highest Sorter), n

SELECT * FROM employee A WHERE 3=(select count(*) +1 from employee B where B.salary > A.salary) This gets the 3rd highest salary; can somebody explain the logic behind this query and how it works.

In Foursquare, the user who has the highest score for a place in the last N days is awarded the Mayorship of that place. What is the most efficient way to implement that? A user could have checked in

I have a working directory with a large number of subfolders (i.e 1190A, 1993A etc). '/working/1190A' '/working/1993A' I would like to recursively create a certain directory tree within each subfolde

I have a code that contains an ASPxGridView and a ASPxCheckBox and Label within in like: <dx:ASPxGridView ID=gvTableSearchHomes runat=server DataSourceID=XmlHomes Width=341px CssClass=tab