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.
8
votes
2answers
300 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
99 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 ...
0
votes
0answers
10 views
A Tour of Go, Equivalent Binary Trees: Am I “leaking goroutines”? [on hold]
I started reading about Go a couple days ago, and today I went through A Tour of Go, doing a couple of the exercises.
For Equivalent Binary Trees, the solution I wrote attempts to return early if it ...
6
votes
4answers
499 views
Binary Search Tree C++ Implementation
I've implemented a simple binary search tree for practice purposes:
...
0
votes
1answer
27 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
42 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
75 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
47 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 ...
2
votes
1answer
34 views
Print all nodes that are at distance k from a leaf node
Given a binary tree and a positive integer \$k\$, print all nodes that
are distance \$k\$ from a leaf node.
Here, the meaning of distance is different from the previous post.
Here, \$k\$ ...
3
votes
3answers
120 views
Find floor and ceiling in the BST
Find ceiling and floor in the BinarySearchTree. Looking for code-review, optmizations and best practices.
...
1
vote
3answers
58 views
Find all possible interpretations of an array of digits
Consider a coding system for alphabets to integers where 'a' is
represented as 1, 'b' as 2, .. 'z' as 26. Given an array of digits (1
to 9) as input, write a function that prints all valid ...
4
votes
3answers
49 views
Retrieve Father and Child structure in a Database Table
I have a table with this schema:
CREATE TABLE [td].[MyTable] (
[ID] [int] NOT NULL
,[FatherID] [int] NULL
)
(Note: I have excluded all the columns not ...
0
votes
1answer
43 views
Maximum sum between two leaf nodes
Given a binary tree in which each node element contains a number. Find
the maximum possible sum from one leaf node to another.
The maximum sum path may or may not go through root. For ...
0
votes
1answer
65 views
Check if two nodes are cousins in a Binary Tree
Given the binary Tree and the two nodes say ‘a’ and ‘b’, determine whether the two nodes are cousins of each other or not.
Two nodes are cousins of each other if they are at same level and have ...
3
votes
3answers
82 views
Delete alternate nodes of a linked list
If the linked list is 1->2->3->4 then the output should be 1->3. If the linked list is 1->2->3->4->5, then the output should be 1->3->5.
The question is attributed to GeeksForGeeks. I'm looking ...
1
vote
1answer
33 views
Remove all nodes which don't lie in any path with sum >= k
Given a binary tree, a complete path is defined as a path from root to a leaf. The sum of all nodes on that path is defined as the sum of that path. Given a number K, you have to remove (prune the ...
1
vote
0answers
32 views
Extract Leaves of a Binary Tree in a Doubly Linked List
Given a Binary Tree, extract all leaves of it in a Doubly Linked List (DLL). Note that the DLL need to be created in-place. Assume that the node structure of DLL and Binary Tree is same, only the ...
2
votes
2answers
72 views
Building tree structure based on flat objects - second follow up
This is a follow up on this question which is a follow up on this question
This follow up is created, because the class in question contained something, which didn't do what it should do.
Based on ...
1
vote
1answer
44 views
Building tree structure based on flat objects - follow up
This is a follow up on this question
I have implemented some changes to the class below and also added the method AddChildRange() to the ...
2
votes
1answer
34 views
Try to implement comments tree for django
I tried to create implementation of tree for comments. I want use it in Django to store comments. Please tell me how to implement it much simpler, without recursion, to find child nodes.
...
4
votes
2answers
109 views
Building tree structure based on flat objects
Description
A List<UnrelatedObects> is returned by a 3rd party webservice, which will then be transformed to a ...
1
vote
2answers
49 views
Check if all leaves are at same level
Check if all leaves are at same level. This question is attributed to geek for geeks. Looking for code-review, optimization and best practices.
...
0
votes
0answers
49 views
Convert a doubly linked list into balanced binary search tree in-place
Given a doubly linked list which has data members sorted in ascending
order, construct a balanced binary search tree which has same data
members as the given doubly linked list. The tree must ...
4
votes
1answer
55 views
A Quadtree implementation with Colliders
I have created a QuadTree in Java and would like a general code review or suggestions.
...
7
votes
3answers
346 views
Hierarchical k-ary tree in C without relying on RAM
I created a k-ary tree in C to be used as an easy and efficient way to organize "UML-like" data in embedded devices. The left node is at the lower logical level (a child) while the right node is at ...
10
votes
1answer
122 views
Good performance when predicting future game states
This question is about my answer to this king-of-the-hill challenge on Code Golf. In short, the purpose of the challenge is to code a slime that, trough various possible moves gains control over an ...
1
vote
0answers
54 views
Deepest left leaf node in a binary tree
Given a Binary Tree, find the deepest leaf node that is left child of its parent. This question is attributed to GeeksForGeeks. Looking for code-review, optimizations and best practices.
...
3
votes
1answer
51 views
Reverse values of alternate nodes of the tree
Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree.
Given tree:
...
0
votes
1answer
48 views
Return the next right node
Given a binary tree, return the next right node. This question is attributed to GeeksForGeeks.
For example, consider the following Binary Tree. Output for 2 is 6, output for 4 is 5. Output for 10, 6 ...
1
vote
1answer
74 views
Get the levels of a binary tree
Given a binary tree, return a list of each level.
I'm looking for a general review and a mention on best-practices, optimization, and verification of my complexities.
Time complexity: \$O(n)\$
...
1
vote
0answers
29 views
Optimizing Recursive Quadtree
I have a written a quadtree program in Python 2.7 to cross-correlate large catalogs with each other i.e. find the common objects in the catalogs based on their position. The problem is that it's still ...
3
votes
3answers
187 views
Find all nodes in tree, without a sibling
Find all nodes of trees, without siblings.
This question is attributed to GeeksForGeeks.
I'm looking for code reviews, optimizations and best practices.
...
1
vote
1answer
65 views
Find K distant nodes
Find all nodes, which are at a distance of k from the input node.
Input:
target = pointer to node with data 8.
...
3
votes
1answer
48 views
Construct KD-Tree in Java
I want to construct KD-Tree from unsorted List of points in the plane (i.e. 2-KD-Tree). To do so I used the method from Wikipedia: http://en.wikipedia.org/wiki/Kd-tree#Construction This is my code:
...
6
votes
2answers
275 views
Binary Search Tree implementation using templates
I wrote this implementation using templates. It works fine and as expected. Just want to know if this can be improved. I have some specific questions too at the end. Please feel free to critique to ...
9
votes
4answers
327 views
Do I need Generics for these node and tree classes?
I want to implement KD tree. I have defined class Node as follows:
...
-2
votes
1answer
102 views
Given a BST, transform it into greater sum tree
Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater than that node. Diagram is here.
Looking for code review, optimizations and best practices.
...
6
votes
2answers
185 views
Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree
Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree.
Given tree:
...
2
votes
4answers
87 views
Detect if a tree is complete binary tree
Detect if tree is complete binary tree. This question is improvement over previously asked here. Looking for code-review, optimizations and best practices.
Verifying both space and time complexity to ...
2
votes
1answer
45 views
Folding with trees
I was trying to implement a foldTree function to generate a balanced binary tree from a list of values using foldr (Question 2 ...
1
vote
1answer
38 views
How am I supposed to write a binary tree (S-Expression) pretty printer in C?
OK, I feel like I am doing something really wrong here. I'm just trying to create a binary tree, and a pretty printer for it. My approach is looking so bad I can't even...
...
4
votes
1answer
85 views
Detect a complete binary tree
Detect if a tree is complete binary tree or not. Looking for code review, optimizations and best practices.
...
4
votes
1answer
96 views
Segment tree implementation
I'm learning segment trees and their implementation. For the purpose, I tried solving the problem on CodeChef.
Full code here
My tree implementation is as follows:
...
2
votes
1answer
46 views
Basic binary Tree in JavaScript
I wrote a basic binary tree in JS. Can anyone give me some feedback about my code?
I just want to know if this is the right approach, and how I can improve the tree. I am new to JavaScript and data ...
1
vote
1answer
247 views
Convert sorted linkedlist into balanced binary search tree
Convert a sorted linkedlist into a balanced binary search tree. Looking for code-review, optimizations, and best practices.
...
5
votes
2answers
339 views
Missing level of technical depth (Flatten Tree)
I recently have given a coding test in a reputable IT company. There were three coding questions.
They refused me by saying that
as we felt they didn't demonstrate the level of technical depth ...
7
votes
5answers
547 views
Treap implementation in C
I was needed a SET-like data structure written in pure C for some university class, so I've implemented a simple one - the Treap (or cartesian tree).
Please check if everything is okay (actually, I'm ...
5
votes
2answers
177 views
Print binary search tree by levels function implementation
I do not like this implementation as is seems too much complicated. My idea was to implement some BFS algorithm variant.
Some points to notice:
I use one queue.
In the begining put the tree ...
3
votes
2answers
105 views
Morris inorder traversal
Morris Inorder traversal - an algorithm for in-order traversal, of a tree, without recursion of extra memory. Looking for code review, optimizations and best practices.
...
6
votes
4answers
646 views
Basic Postfix Calculator in Java
I recently posted some sample code that I was providing students with and got great feedback so figured I post another one of the examples I will be providing students with. (See Simple Example of an ...