I have class SimpleTree just basic binary tree: And the problem is to write method: Where level is the level of the elements in some tree (root level == 0). For example level == 1: Only LEFT leaf of DELETED elements is saved, if we dont have such -> save the right. Answer Your tree seems to be a recursive
Tag: binary-tree
How exactly does return statement work in recursive function?
I’m having a hard time approaching any binary tree questions and most of them are recursive, so I decided to detour and start from the basics again. This is basically the pre-order traversal list. I’ve identified two ways that can give me the correct results if there is at least 1 node, but I’m unsure about the intrinsic differences between
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.
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
Change node values to their heights in a binary tree
My task is to change the values of nodes to their heights in a binary tree. By the condition of the task, you need to change all the values in 1 pass of the tree, but you can violate this condition …
Java – Binary Tree pointer still null after initialization?
This question is very abstract and thus very hard to describe or search for, thus why I am here. It’s a very simple question however. I have the following class: What happens if I have: Notice that child is a pointer that points to either the left or the right child of root. BUT, what happens if I instantiate the
Trying to print top view of a tree using two if statements
Problem Statement You are given a pointer to the root of a binary tree. Print the top view of the binary tree. You only have to complete the function. My Code: The two if statements are executed every time the function is called, but I need only one of them to execute. I tried switch but its giving constant expression