Questions tagged [binary-tree]

-1

votes
0

answer
31

Views

JSON validation on Java

I want to make validations on the backend side, for a JSON structure received from the client. JSON example from frontend: { 'status': { 'type': 'string', 'value': 'test' }, 'validFrom': { 'type': 'number', 'value': '123123123' }, 'customerData': { 'type': 'map', 'value': { 'customerName': { 'type':...
Alex
1

votes
1

answer
55

Views

One-line output operator for a binary tree

I wrote a simple binary tree class in C++ and want to add an output operator to it. My first attempt was: ostream& operator
Erel Segal-Halevi
1

votes
2

answer
740

Views

How to print A binary tree?

how can i send (node.data) from SortTree Class to TreePrinter then used to print A Tree . import javax.swing.tree.TreeNode; public class SortTree { static Node root; TreePrinter type =new TreePrinter(); class Node{ int data; Node left, right; Node(int d) { data = d; left = null; right = null; } } N...
Adeeb_Alqubati
1

votes
1

answer
56

Views

Binary Node Tree, wrong father and sons

I'm having a hard time printing the following tree: ----------t1:---------- tree:(((1),2,(3)),4,((5),6,(7,(8)))) ----------t2:---------- tree:(((1),2,((3),4)),5,(6,(7,(8)))) ----------t3:---------- tree:((1),2,(3,(4,(5,(6,(7,(8))))))) ----------t4:---------- tree:((((((((1),2),3),4),5),6),7)...
Yuki1112
1

votes
1

answer
48

Views

How to compare the shape of one SortedSet to another in C#

I'm trying to compare the shape (by shape, I mean the shape of the binary tree) of one SortedSet at a certain index of a List of SortedSets against all the rest of the SortedSets in that same List. I've tried to look up ways to compare Binary Trees, but I don't know how to do it with SortedSets inst...
Snaps56
1

votes
0

answer
69

Views

Binary Tree size function python

I'm a beginner of Python and data structure, I have a problem with designing the binary tree size method, my code and my error are as follows class BinaryTree: def get_left(self): return self.left def get_right(self): return self.right def set_data(self, data): self.data = data def get_data(self): r...
Elena
1

votes
1

answer
238

Views

Binary Tree Visualization - circular tree? (QT)

I was wondering if anyone has any advice on implementing an algorithm for creating a circular 'phylogenetic' type: graphics scene for a binary tree in QT? Something like this: except with the word labels replaced with buttons. I'm currently using QT Elastic Nodes as a template, and have managed to...
laserfart
1

votes
0

answer
245

Views

Dynamically constructing a binary tree using “Node” structure in python

I’m trying to convert a mathematical expression into a binary tree structure using the “Node” type in zss library. I’m using this particular “Node” type because I want to compute the tree edit distance using a function in the same library. Mathematical expressions can be in different for...
SriniShine
1

votes
2

answer
47

Views

How to display the next element in sequence for a balanced binary tree? (inorder)

So I'm creating ordered set ADT, using a tree implementation for an assignment. And one of the requirements is implementing an iterator for the set. And I'm having some trouble as to how I'm supposed to return the next element in sequence, when I'm using recursion to traverse the tree. I was thinkin...
Doe J
1

votes
1

answer
39

Views

returning result from binary search tree

I'm trying to determine if a value is found in the binary search tree. If it's found, the value is printed. If not, a message is printed saying it wasn't found. My problem is that even when the value is found, the message is printed saying that it wasn't found. My result seems to reset even after...
qu2021
1

votes
2

answer
55

Views

Javascript Binary Search Tree methods not working

I am trying to build this simple Javascript Binary search tree. I have simply created the addItem method for the tree, but no item seems to get added to the tree. I have divided the addItem method into several other methods to ensure that the tree reference is passed properly without any errors. I...
raiyan106
1

votes
1

answer
47

Views

Induced height imbalance in AVL tree

If a node is inserted in an AVL tree, it might happen that one of the nodes in the path to the new_node would lose height balance. But my question is if that node is fixed, can other nodes above it (the ancestors till the root) would still retain height imbalance (in case they lost the balance earli...
enig123
1

votes
1

answer
321

Views

push_back() binary tree into vector

I'm trying to put all the elements from a binary search tree into a vector, in order. Here is the function: edit: adding instructions for clarity. Write a class for implementing a simple binary search tree capable of storing numbers. The class should have member functions: void insert(double x) bool...
Kenneth Freeman
1

votes
0

answer
106

Views

Creating an ArrayList of Arraylist of paths for a Binary Tree?

I've searched this problem up before but looking at answers to previous problems doesn't seem to help me, and I'm not sure how to test my function on a binary tree because you can't add to a binary tree (I think?) Basically, for practice examples for an upcoming exam, my professor gave us a problem...
vp123
1

votes
1

answer
24

Views

Insert into a Binary SearchTree that impliments Generics

I am trying to create a binary search tree that impliments generics. i am struggling with inserting nodes after i have inserted the Root of the tree, it is most likely my insertion logic that is wrong. but i can not see how. My question is, what is wrong with my insertion logic because i can not ge...
Ruan Labuschagne
1

votes
1

answer
83

Views

Swift: How does this create a binary tree?

So I am following an online tutorial and I understand everything except this part. The person explains to me this creates a binary tree so to speak where one item is linked to two items. In this case a page is linked to two pages. I don't understand how this works in this example where struct Advent...
Curt Rand
1

votes
1

answer
208

Views

View of a binary tree from 45 degree

So I am not asking diagonal view of a tree, which fortunately I already know. I am asking if I view a tree from 45-degree angle only a few nodes should be visible. So there is a plane which at an angle of 45-degrees from the x-axis. so we need to print all the nodes which are visible from that plane...
Gurinder
1

votes
0

answer
161

Views

Making A simple Derivative Parse Tree in Python 3.0

So I made a parse tree code(which is mostly taken from the book 'Problem Solving with Algorithms and Data Structures using Python') and from there I am trying to find the derivative of the expression(which is parsed in the parse tree code). Some simple conditions that my teacher gave us is that we c...
Jr194
1

votes
0

answer
36

Views

How to switch from using a stack to just using the parent field in a parse tree?

I have a homework assignment about making a parse tree after taking in a fully-parenthesized string and then printing the parse tree. It asks me to modify a couple things and one of those is to change the way we keep track of the parent node. In the original code they use a stack to do so, but my in...
Jose Avalos
1

votes
1

answer
156

Views

Finding the length of compressed text (Huffman coding)

Given a text of n characters and a Binary tree, generated by Huffman coding, such that the leaf nodes have attributes: a string (the character itself) and an integer (its frequency in the text). The path from the root to any leaf represents its codeword. I would like to write a recusive function tha...
zerrus011
1

votes
1

answer
31

Views

Can't delete a grand parent node in BST program

This Binary search tree program crashes when i try to delete a node having grand children. Such a node is '80'. I can delete any other node successfully and do other operations like traversal, Finding height and finding minimum or maximum element. Please look at the code and tell me if i need to pro...
LetmeLearn0089
1

votes
2

answer
135

Views

ZigZag binary tree traversal in C++

I am trying to attempt zig zag traversal of binary tree. But I am stuck at one type of test cases, i.e., when the tree is not balanced. If I give my input as 3 3 9 20 null null 15 7 for a binary tree which looks like this: 3 / \ 9 20 / \ 15 7 I get output: 3 20 9 0 If my input was 3 9 20 1 n...
Akriti Anand
1

votes
1

answer
443

Views

Prolog binary tree search

I've encountered this problem: Write a PROLOG program that given a binary tree of with integer numbers stored in the nodes. Write a program that returns the maximum value stored in the tree. For example, given the input [4,[1,[],[]],[7,[],[]]] the algorithm should return 7. I guess I have to use BFS...
newbie
1

votes
0

answer
119

Views

Code::Blocks: Cannot open file: ../libgcc/unwind-sjlj.c

I've been working on this project for a bit now and I'm running into this issue that I can't solve. As a preface, the program builds a binary tree from data from a file, then the tree can grow, and the new complete information is written over that original file. To do this all with a single informa...
Jorge Zazueta
1

votes
1

answer
1.1k

Views

Print Binary Tree in C

How can i display an binary tree in c?, like this 37 / \ 16 3 / \ / \ 9 26 58 81 \ / \ 35 55 74 i can display level by level 1 23 4567 89 but i need draw this BTs in the exactly format void printLevel(NoArvore * node , int level) { if(node != NULL && level == 0) { print...
ezequiel
1

votes
0

answer
49

Views

Insert and remove in AVL tree C

I have a problem in inserting and removing an AVL tree, the rotations at the time of inserting and removing from the list, the part of the binary tree as far as I tested was working fine, but with several modifications that were made I can not guarantee that everything is alright, I'm in a hurry bec...
1

votes
0

answer
93

Views

Pre-Order Traversals Of All Possible Binary Trees Given In-Order Traversal

I was looking at questions on binary trees, and I came across the following: Given the in-order traversal of a binary tree, print the pre-order traversals of all possible binary trees satisfying the given in-order traversal. For e.g, if the in-order traversal is: {4, 5, 7} The possible trees are: 4...
user162417
1

votes
0

answer
41

Views

C# Binary tree Graphical/Visual control

I have data in the MSSQL database and it is a binary tree. The users are connecting to each other as a binary tree network. I need to show them in a visual graphical view. Also, it should allow to search a username and load it as the root node to show the child nodes. Is there a C#/.NET control or a...
Yma
1

votes
1

answer
80

Views

Python 3: Binary Search Tree failed to set nodes

so I have been working on this class project implementing a binary search tree. The professor wants us to make the private recursive while make the public one simple. (like when to insert_element(50), it calls a private function recursive_insert(50, self.__root) to solve). My insertion function runs...
Joanne Teng
1

votes
0

answer
69

Views

Difference between using global variable and pointer variable?

I have been coding a binary tree problem of finding maximum between ancestor and a node.I have coded it in two ways.But it provides two different answers.How? int res=INT_MIN; int maxDiff(Node* root){ if(root==NULL){ return INT_MAX; }else if(root->left==NULL && root->right==NULL){ return root->data;...
Ahamed Yasir
1

votes
2

answer
136

Views

Python variable value assignment in recursion

There are two solution for a problem: Problem is : Enter the root node of a binary tree and an integer to print out the path where the sum of the node values in the binary tree is the input integer. A path is defined as a path from the root node of the tree to the next node until the leaf node passe...
Kyan
1

votes
1

answer
107

Views

Insert in binary tree using recursion

I am trying to implement binary tree NOT binary search tree. I spent a good amount of time to write insert operation using recursion but did not get. It should be a complete tree that is filling from left to right. Can someone help me with that?Preferably in Java. The following is the iterative w...
Harsha
1

votes
0

answer
66

Views

Creating a pedigree chart layout with graphviz

Graphviz has some powerful graph layout algorithms. But can it lay out a binary tree as depicted below? With the top node in the middle of the page, with each parent fanning out to the side. Which graphviz tool could I employ to recreate this layout?
Bram
1

votes
1

answer
100

Views

Binary Tree Level Order Traversal in leetcode

got error when tried to run the code 'terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc' Code: #include using namespace std; class Solution { public: vector levelOrder(TreeNode* root) { int d = height(root); vector lol[d]; vector ans; queue q; if(root!=NULL) q.p...
Sunny Sahu
1

votes
2

answer
406

Views

How to make a Binary Search Tree a Complete Binary Search Tree in Java?

The accepted answer can make a Perfect tree (which is also a Complete tree). Although it cannot make a Complete tree without being Perfect. It was the closest answer to my request though. To make a compete the without being Perfect too, you could remove the rightmost leaves of the tree. 1. Problem:...
1

votes
2

answer
32

Views

Binary Tree Node Location and Helper Dictionary

Thanks for your help Background I have a question about locating nodes in a tree. I have a simple binary tree. Each node has a piece of data in it. Lets say it looks like this: a / \ b c Where a=root, b=root.left, c=root.right The tree is not created manually. Let's say I get a request to add new...
JW2
1

votes
1

answer
33

Views

Check if a binary tree is a binary search tree - Why doesn't my code work?

You are given the root of a binary tree and you must check if it's a binary search tree. Note that the value of all nodes are distinct (It's a question from Hackerrank in the Trees section). This is the link I really can't figure out why my code doesn't work. Makes no sense. Here's my code in java b...
user10210735
1

votes
1

answer
59

Views

String based Binary tree and insertion

The Binary tree does not use comparison rather, the user inputs the String name of the node they want to add the left or right child, if the node already has a child for either of the two and it will not overwrite it. I'm having some difficulties, it doesn't stop it from overwriting a pre-existing N...
Icarus Will
1

votes
0

answer
94

Views

Convert Binary Tree To Doubly Linked List - Java

Help me with this problem please. It's taken from Educative.io course called 'Coderust 3.0: Faster Coding Interview Preparation' Problem description: Convert a binary tree to a doubly linked list such that the order of the doubly linked list is the same as an in-order traversal of the binary tree. A...
user10210735
1

votes
1

answer
96

Views

Store a counter in a binary tree recursive function in java

I am doing an exercise for school where I have to create a method in java (at most O(n) time) that stores the order in which a given value appears in a binary tree, whether in post-order, in-order or pre-order traversal. So far I have working code, but the counter doesn't increment properly. Can som...
Brent R

View additional questions