Questions tagged [tree]

12356 questions
1

votes
1

answer
17

Views

AST how to deal with empty nodes

I am building an expression evaluator using Java, JFlex(lexer gen) and Jacc(parser gen). I need to: generate the lexer generate the parser generate the AST display the AST graph evaluate expression I was able to create the lexer and the parser and the AST. Now I am trying to make the AST graph using...
Anonimista
1

votes
1

answer
41

Views

Create a Tree/Trie from a word

I need some help to create a javascript algorithm that builds a tree out of a word. The nodes of the tree are the letters of the word that are always in alphabetical order. Ex. 'balance' should be this object: const tree = { b: { l: { n: {} }, n: {} }, a: { l: { n: { } }, n: { }, c: { e: { } }, e: {...
Thiago Caramelo
-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
0

votes
0

answer
11

Views

Which one is a better BFS algorithm

Given a binary tree, print all of its node values level by level. Which of the 2 methods below is better performance wise and readability wise? def bfs_queue(root): q = collections.deque(root) while q: node = q.popleft() print node.val if node.left: q.append(node.left) if node.right: q.append(node.r...
user1008636
0

votes
0

answer
15

Views

How to improve the performs of the monte carlo tree search algorithm?

I'm trying to implement Monte Carlo tree search to play 9-board tic-tac-toe in Python. The rules of the game is like the regular tic-tac-toe but with 9 3x3 sub-boards. The place of the last piece is placed decides which sub-board to place your piece. It's kind like ultimate tic-tac-toe but if one of...
Vera
1

votes
2

answer
13

Views

how to implement level order print for MaxHeap

I'm currently making a MaxHeap program and I need to print my heap in level order. How can this be done? Do I create a method to print the heap in level order inside of my heap class or would I do it in my main class? I know for like my binary search tree project i used iterative methods and called...
1

votes
1

answer
126

Views

Machine learning algorithm score changes without any change in data or step

I am new to Machine learning and getting started with Titanic problem on Kaggle. I have written a simple algorithm to predict the result on test data. My question/confusion is, every time, I execute the algorithm with the same dataset and the same steps, the score value changes (last statement in th...
YoungHobbit
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
45

Views

Dynamically responding to an unpacking assignment statement

In an unpacking assignment statement, can the assigned object inspect the number of variables it is being assigned to? class MyObject: def __iter__(self): n = some_diabolical_hack() print(f'yielding {n} vals') return iter(['potato']*n) Something like: >>> x, y = MyObject() yielding 2 vals >>> a, b,...
wim
1

votes
2

answer
6.5k

Views

Looping through tree hierarchy in python?

I'm new here and pretty new to python! We got a homework, and I already was able to do rest of it, but one problem remains: If I have a tree hierarchy like this: root = [ parent1 = [ child1, child2 = [ sub_child ] child3 ], parent2 = [ child1, child2 ] ] And they are all instances of one class named...
Patrik Lippojoki
1

votes
1

answer
7k

Views

How to set double click to edit a Table cell in SWT/JFace?

Is it possible to change the default behavior of SWT/JFace to enable cell editing only with double clicking? The way it is now (with single click) is hard to select a table row without bringing the text field up. Here is a self-contained code snippet: package table.editing; import org.eclipse.jface....
freitass
7

votes
1

answer
212

Views

Modify existing yaml file and add new data and comments

I recently saw that the go yaml lib has new version (V3) with the nodes capabilities (which in my opinion is a killer feature :) ) which can helps a lots with modifying yamls without changing the structure of the file But since it is fairly new (from last week ) I didn't find some helpful docs and e...
Rayn D
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
0

answer
73

Views

compaction not triggered in rocksdb

I have trouble triggering compactions during a bulk insert with HASHSKIPLIST memtable in rocksdb. I use PlainTable SST file format. Memtable size is set to 64MB and number of write buffers is 6. While inserting 200Million data, the number of level0 files goes around 80+ and i dont see compaction bei...
krithikaGopalakrisnan
0

votes
1

answer
14

Views

Vectors pointers with vector slices for Tree generation from preorder and inorder vectors

I'm getting the following error: solution.cpp: In member function buildTree Line 26: Char 62: error: no matching function for call to 'Solution::buildTree(__gnu_cxx::__alloc_traits, int>::value_type*, std::vector*)' root->left = buildTree(&preorder[index],&inorderslice); ^ In this code: class Solut...
JoaoAntunes
1

votes
2

answer
386

Views

Smallest element in tree that is bigger than x

If I want to find the smallest element in a tree that is bigger than an element x, would this be a correct way to do it? class Node { int data; Node left, right; } Node root; public Integer successorOf(int x) { return successorOf(x, root); } private Integer successorOf(int x, Node n) { if (n == nul...
micro
1

votes
1

answer
301

Views

how to make decision tree look nice in R and/or Jupyter?

I'm very new to R, and decision trees in general, so sorry if this is a dumb question. I am trying to make a decision tree in R. It's working, but when it does not look nice. It looks smushed. I know it looks better when I expand the image, but it doesn't look good in Jupyter either. Here's my cod...
Emily Lerman
1

votes
1

answer
241

Views

SPI without CS pins configured (BeagleBone Black)

I don't need to use the 'stock' CS signals for SPI in BeagleBone Black. Can I just omit their configuration in DTBO to save a couple of GPIOs? In other words, (1) will SPI work properly? (2) may it cause a GPIO conflict? Here is a DTS fragment example for SPI1: .... [email protected] { target = ; __overlay...
Sergey Manucharian
1

votes
1

answer
687

Views

Clarification of decision tree surrogate splits

I have a question regarding the output of an rpart classification tree in R. Where there is missing values, a surrogate split is used. Here is an example. Surrogate splits: ## bmi < 21.51 to the right, agree=0.858, adj=0.632, (0 split) Is the agreement calculated as, the proportion of cases...
Rory Mcstay
1

votes
1

answer
47

Views

Red-black tree insertion task

I would like to ask in which order should I add elements: 1,2,3,4,5,6,7, so that tree would be fully balanced and children of root node should be red.
Mirjan Pecenko
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
38

Views

How to implement template methods for a tree that has only two types of nodes?

I'm implementing a tree where each Node is only either an InnerNode or a Leaf which I would normally implement like this: class Node { public: virtual ~Node() = default; }; class InnerNode: public Node { std::vector children; ... }; class Leaf: public Node { ... }; Now I would like to have a templat...
eyelash
1

votes
1

answer
18

Views

Designing data structure which can decrease range in lgn

I was asked in an exercise to design a data structure which can handle the following methods in logarithmic time complexity (lgn): Insert(x): Inserts x to the data structure Find(x): Finds if x exists in the data structre Decrease(x, y): Adds negative value y (y
ron333
1

votes
1

answer
14

Views

Eclipse RCP ProjectManager Tree Element cut off

I have an Eclipse RCP 3.x application with a Project Manager Tree Viewer in its own part.. When I expand the root (parent) of the tree, the child's last character is slightly cut off by about 2 pixels. However when I expand that child's tree, it is no longer cut off but the child of it has its last...
Marv
1

votes
0

answer
90

Views

Python Tree with unknown Height

Assume I have 2 columns: OP_CODE Additional Work a b a c a b d b e c d f d g d e f g What I have to do is, I have to take a value from column OP_Code...
Shubzumt
1

votes
1

answer
434

Views

Multi Level Marketing SQL Query to calculate turnover of the team

I have a users table that looks someting like this : ID NAME 1 Robin 2 Edward 3 Donald 4 Julie The 2nd table user_tree ID USER_ID TREE 1 1 ['2','3','4'] 2 2 ['3','4'] 3 3 ['4'] 4 4 [] The 3rd table orders ID AMOUNT USER_ID 1 150 2 2 300 3 3 200 4 4 500...
user2776338
1

votes
1

answer
71

Views

How to create an easy to explain regression model in Python with categorical features?

I have a dataset that looks like this, where each row is a user. gender age_group c1 c2 c3 total_cost F 0-10 10 F1234 3456 135.2 F 65-100 10 G5143 876 523.6 M 18-35 15 F3457 876 98.5 F 0-10 10 F1234 545 1052.1 M 35-65 2...
sfactor
1

votes
0

answer
35

Views

AVL tree insert case need a clarify

I read several online document about implementing AVL tree using balance factor(Not using a height data field in Node structure), when insert into the tree, there is one case I could not figure out. The document is from here(also from here has similar function) , the balance factor is defined as hei...
wangdq
1

votes
2

answer
454

Views

Rendering a Tree in Python

I had dataset like below: A B 1 2 5 3 2 5 3 Below code gives me the following output: def all_paths(table, root): # convert table structure to adjacency list children = {} for node, child in table: if child: children[node] = children.setdefault(node, []) + [child] # generator for it...
Shubzumt
1

votes
0

answer
159

Views

What are the advantages of Breadth First Search over Iterative Deepening Depth First Search and vice versa?

They both find the shortest path and I know BFS uses way more memory, but are there any clear advantages BFS to IDDFS and vice versa.
Cathal Hughes
1

votes
0

answer
333

Views

Angular (2) TREE . Double click issue. Not working properly.

Double click in angular tree component is not working, here's the sample of code I'm trying to use. Do I need to write anything else in my code, so that it will work?? Please help me on this one. Thank you. import { Component, Input } from '@angular/core'; import { TreeNode, TreeModel, TREE_ACTIONS,...
TheDoozyLulu
1

votes
0

answer
459

Views

Rails Indexing: Adding :btree index type to migration

I'm trying to figure out how to run a migration that adds the B-Tree index type to an index. I tried running rails g migration add_index_to_recipes which gave me an empty migration: class AddIndexToRecipes < ActiveRecord::Migration[5.0] def change end end then I modified the migration like so: cla...
Belder
1

votes
0

answer
235

Views

Is there a hash tree designed for complex data structures?

I have a JSON object with private data. It has the following (complex!) structure: { name: 'JB', age: 35, children: [ { name: 'Alice', age: '5', favColor: 'pink' }, { name: 'Bob', age: '8', favColor: 'blue' }, { name: 'Charlie', age: '9', favColor: 'green' }, ] } I want to create a hash tree tha...
nervous-energy
1

votes
1

answer
275

Views

convert non balanced binary search tree to red black tree

Is it possible to convert a non balanced BST (the size of the tree is n and the height is h) to RBT in time complexirty of O(n) and space complexity of O(h)?
Tal
1

votes
0

answer
37

Views

Can Merkle tree tell if more than one copy of the object exist in it?

With Merkle root hash, and Merkle path, one can verify if a given object (i.e a transaction) exist in a Merkle tree. But is it possible to tell there is no other duplication of the object in the tree. For example, if I have the Merkle root of a list of transactions and the Merkle path of one transac...
Leo Zhang
1

votes
0

answer
105

Views

In Java how do I create a structured tree using FileVisitor

Given a starting path I want to create a tree like object representing the filesystem using Java, showing all the folders down to level x but not ordinary files. . So using FileVisitor I know that every time just before Im going to browse a new subfolder that the preVisitDirectory() method will be c...
Paul Taylor
1

votes
0

answer
143

Views

a value of type Node * cannot be used to initialize an entity of type Node *

I'm writing a simple tree traversal procedure. I have a class for a node in the tree which holds the node's number, a vector of pointers to it's children and some data. I pass this a pointer to a Node to some function which does BFS from that node. class Node { public: int num; long long weight; l...
Yakov Dan
1

votes
1

answer
120

Views

Reinforcement Learning: fine-tuning MCTS node selection and expansion stage with inaccurate values

I am implementing a Go playing program roughly according to the architecture of earlier versions of AlphaGo(AlphaGo Fan or AlphaGo Lee), e.g. using policy network, value network, and Monte Carlo tree search(MCTS). Currently I have trained a decent policy network and an insensitive value network, and...
Zhao Chen
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
34

Views

How do JavaScript transformers process different AST structures?

I am currently playing around https://astexplorer.net/. In there, you can choose different parsers (acorn, babylon, esprima) that generate different structures of AST. You can also choose different types of transformers (babel, prettier, tslint) that convert the AST into the resulting source code. S...
galibee

View additional questions