A tree is a graph in which there is exactly one path between any two nodes. It is often used as a hierarchical data structure.
2
votes
2answers
81 views
Binary Search Tree in C++
I'm writing C++ for the first time and wanted to implement a BST. I come from writing C, so I tend to write code in that way. I'm trying to wrap my head around smart pointers, but can't seem to get ...
3
votes
3answers
99 views
AVL tree for inserting and searching
I have made an AVL tree. It works and does what it needs to do. I only need it to insert and search. I am comparing how long it takes to load and search a dictionary file in relation to other various ...
1
vote
2answers
100 views
Octree code performance
I'm using a simple Octree in my program, wanted to know if my implementation could be faster. It is part of this program: https://github.com/Mortis69/rendera
Octree.H:
...
1
vote
0answers
30 views
Treap with implicit keys
I implemented an implicit treap and tested it a little. It works fine but I'd like to know if there are ways to improve/simplify things and/or if some parts are incorrect. Later, I'll augment code to ...
1
vote
1answer
27 views
insertBST exercise
I'm just learning Haskell on my own, and did an exercise to implement insertBST.
Is this idiomatic Haskell?
...
0
votes
0answers
26 views
Implementing Functor Instance for `ITree`
Looking at this Typeclassopedia exercise, I typed out foldTree on the following type:
...
0
votes
0answers
48 views
Freeing a binary tree data structure in C
I have this function that I hope to be a good alternative to the recursive (thus performance expensive) approach.
...
17
votes
2answers
477 views
Where equations are born and mutants are buried
I've read up on genetic programming yesterday so I figured I'd try to implement something myself. I would like the main focus to be on whether or not I've implemented the idea behind it correctly.
...
4
votes
1answer
48 views
Implement `fold` on a “Rose Tree”
Given the following algebraic data type, a Rose Tree:
data Tree a = Node {
rootLabel :: a,
subForest :: [Tree a]
}
I attempted a ...
1
vote
1answer
57 views
Trinary tree insertion and deletion
I have worked on the trinary tree problem insert and delete. Can anyone look at it and tell me how it is?
TrinaryNode.java
...
5
votes
3answers
393 views
Building a parent/child tree relationship
I have a problem: build a tree relationship parent/child like this one:
Can you review this piece of code please since I am convinced it could be improved?
...
1
vote
2answers
49 views
Binary search tree with templates
I am currently attempting to become proficient in C++ and started by implementing a basic binary search tree. Most of the programming I have done is in Ada, Python and C.
I would like to be able to ...
0
votes
0answers
7 views
Proper tree NoSQL structure with focus on full-text searching [migrated]
I developing an app with tree(folder-file) structure, on which I should perform full-text searches with MongoDB. I did a research on the best tree structure practices and found this great article, but ...
2
votes
0answers
43 views
Time Limit Exceeded for Code Chef problem Rendezvous
I am trying to solve a problem Rendezvous in code chef.
Problem Statement:
Given number of cities and routes between them resembling tree, consider there are two people who are put into ...
3
votes
0answers
14 views
Searching a Join List for an index Attempt #2
Originally I posted this incorrect attempt - Searching a Join List for an index.
Given a JoinList:
...
4
votes
2answers
51 views
Make a map using a splay tree
In my data structures and algorithms class, we were introduced to the splay tree, a BST with the additional property that recently accessed elements are quick to access (because they stay at the top ...
5
votes
2answers
109 views
Finding the weight of the heaviest path in a binary tree
I'm fairly new to Java, arriving in the "future" from C and returning to type safety from Python. I've programmed an algorithm to return the weight of the heaviest path from the root of a binary tree ...
5
votes
1answer
43 views
Retrieve annotation from a tree annotated with a Monoid
Working on this homework from 2013 for self-learning.
For the following Algebraic Data Type:
...
2
votes
0answers
27 views
Adding parent reference to tree nodes
I want to add a parent reference to a tree like structure. The structure can be seen in the first code snippet, which also is how I would use my code, for example inside an angular controller.
...
8
votes
3answers
276 views
Red Black Tree Implementation
I would like some feedback on my red black tree implementation. Anything is fine. I've debugged this and it seems to be working fine, however I may have missed something.
Basically, this is a red ...
4
votes
5answers
192 views
4
votes
2answers
113 views
Creating a better BST
I have created a BST like many others. I am curious to if there is a better way to write it. It seems pretty straight forward, but I feel like it can be improved on a bit.
...
10
votes
2answers
158 views
Validating a Binary Search Tree
This is an implementation of a function to check the property of a Binary Search Tree, that is:
the key in any node is larger than the keys in all nodes in that
node's left subtree and smaller ...
3
votes
0answers
46 views
BK Tree implementation
I'm working on a system that can search for similar images. This involves being able to search by edit-distance, and as such I've implemented a special data-structure called a BK tree. Some notes ...
2
votes
0answers
64 views
Binary Search Tree in Ruby
Binary Search Tree, with preorder traverse. What other methods should I add? How can I improve it?
...
2
votes
1answer
18 views
Sorting of nested categories inside a Common Table Expression
I have a PostgreSQL database which contains (among other things) the following table definition:
...
4
votes
4answers
167 views
4
votes
2answers
47 views
Lopsided Trees and Recursion
The original problem is:
Define the height of a binary tree to be the number of nodes in the
longest path from the root to a leaf. The empty tree is considered to
have height 0. A node is ...
1
vote
2answers
180 views
DFS on a binary tree: marking nodes as visited
I wanted to write depth first search reversal iteratively in Java. Can someone review my code? I'm not that much interested in naming of the variables, but in the structure of the code, i.e. I don't ...
4
votes
3answers
157 views
Inserting a node in Binary Search Tree
I would like any suggestions and improvements for this code, be it generics or my Node class being completely mutable. Should I make it mutable? Is it good? Why?
...
0
votes
2answers
74 views
Populate inorder successor for all nodes
Given a binary tree where each node has following structure, write a
function to populate next pointer for all nodes. The next pointer for
every node should be set to point to inorder ...
2
votes
1answer
37 views
Create Binary, Balanced Tree Attempt #2
Previously, I posted an incorrect implementation of making a binary, balanced tree from a list of a's.
Here's my second implementation:
...
1
vote
1answer
38 views
1
vote
1answer
77 views
Create a complete binary tree
Write a program to create a complete binary tree, which includes an addItem method such that an individual element can be inserted into the tree to maintain the ...
4
votes
2answers
82 views
2
votes
1answer
78 views
Create Binary, Balanced Tree
I wrote a function, which takes a list of Integers, and then makes a balanced binary tree.
Please critique it. I'd like to know know how to make it more concise and idiomatic.
...
4
votes
3answers
114 views
Print all nodes from root to leaves
I've made a function to print all paths from root to all leaves in a binary search tree. I already have an insert function, which I haven't included in the code here as I felt it was irrelevant to the ...
2
votes
0answers
22 views
BST remove implementation
As practise, I implemented a BST and also the remove() method, but I figured I always have to check if the node being deleted is coming from the left child or the ...
4
votes
2answers
478 views
6
votes
1answer
96 views
BFS and DFS tree traversal
I posted some code as part of an answer to another question and I thought it would be a good idea to get that code reviewed also.
Any comments are welcomed, but I am mostly annoyed by ...
3
votes
2answers
95 views
BFS tree traversal Scala
I would love some feedback on the following code for BFS traversal in a binary tree. Is there a cleaner way to write this?
...
3
votes
1answer
62 views
Test if two nodes in binary search tree are cousins
Cousins are nodes at the same level of the tree, with different parents.
They don't have to share the same grandparent.
My solution depends on having a binary search tree with unique elements.
This ...
1
vote
3answers
245 views
Find the Max Width Of Tree
1
/ \
2 3
/ \ \
4 5 8
/ \
6 7
Width of a tree is maximum of widths of all levels.
For the above tree,
width ...
8
votes
2answers
385 views
Run time complexity of printing a binary tree level by level
I have some doubts about running time of following question. The problem is printing a binary tree level by level. For example if tree is like
...
3
votes
3answers
289 views
Binary search tree with tree traversal
Although there are several implementations of binary search tree, I have made my own implementation for practice. The following code does the followoing operation
- Create a binary tree
- search ...
7
votes
4answers
5k views
Binary Search Tree C++ Implementation
I've implemented a simple binary search tree for practice purposes:
...
0
votes
1answer
44 views
Find swapped nodes in BST
A BST has two nodes swapped. Figure out which two nodes.
Looking for code-review, optimizations and best practices.
...
4
votes
0answers
57 views
Equivalent binary trees (structure & values)
I am following the Golang tour and I have been asked to build a couple of functions to manipulate binary trees.
My code runs as expected, but I would like to know if I could further improve my code. ...
3
votes
0answers
86 views
Heterogenous tree in the application domain: How do I represent them?
The Domain
I have three types of items in my domain: ItemA, ItemB, ItemC. (I can't use their real names.) ItemA has one attribute: thing_id. ItemB has 6 attributes: thing_id, name, description, ...
4
votes
1answer
104 views
Implementation of a AVL Tree
I attempted to write a AVL Tree in a functional style and I am hoping to get it reviewed. I am looking for the code to be clear and concise, any opportunity for improvement would be greatly ...