# Tag: tree

## Will TreeMap (BST) be able to solve this question in reasonable time?

You are given a list of up to 10^7 chess players and their ratings r in a competition. However, this competition uses a unique form of rating calculations. The task is to determine the rank of a player after a certain point in the competition. During the competition, the following can occur: A player joins the competition late. They are

## Parent-Child Tree in Java

I was trying to implement a class Node to build a tree of Nodes. Basically, each Node can have children, so if I specify multiple nodes I can build a tree out of it. As an example: The problem I am having problems to solve is to build this tree and find all children of a given element (in this

## How does parameters of a method get stored in stack during a recursive call?

I was doing a leetcode question https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii/ and I am confused on how parameters for a method get stored during a recursive call. If a node gets visited, I wanted to save it’s state that it was visited. When I send two variables, when the stack is getting unwinded the updated variable values are being lost. But if I send

## How to tidying my Java code because it has too many looping [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 10 months ago. Improve this question I have a Node class used to represent a tree structure. Within this class, I’ve defined a print method that

## Checking a tree to be a BST

Here is my attempt to check whether a tree is a BST or not: Code works fine as tested with multiple test cases. But I am not sure if this is a good, clean approach. Recursive method is big it seems. I am dealing with scenarios like null left node, null right node, node itself null, both child nodes null

## How to create a tree by using nodes that point to next brother in Java?

I made a class (shown below) to create a tree where nodes point to the first brother on his own right and the first son (graphically the one on the extreme left). How can i generate and link nodes correctly inside a for loop? So the first iteration of the loop needs to generate and link the first son node

## Transform trie class method to trie node method

my question is how to transform this method from the trie class into a method of the node class that doesn’t use the node as a parameter, I know that I have to make a first method on the tree like this: But I don’t know how to make the transformation of the method into the node class. This is

## Count nodes that are bigger than all their sons

I have to make a programm that counts the nodes bigger than their sons without including the leaf nodes for example: This is my approach: But I can’t see the error Answer Assuming info is an int, this could work for you. I haven’t tested the code, so let me know if there are issues.

## Flat tree of objects while keeping father and child

I have a class Employee which has a tree structure with property team Using Java lambdas I need to flat this tree into same level list while converting Employee class into the following ConvertedEmployee while storing names in dedicated lead and subordinates properties. So ConvertedEmployee is in some sense a node which keeps parent and children. And I need to

## Serialize and Deserialize Binary Tree

I am working on the LeetCode problem 297. Serialize and Deserialize Binary Tree: Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment. Design