All Questions
24 questions
4
votes
2
answers
5k
views
Build a flat List from a Tree structure in Java
I have a Tree structure represented by a List, which I want to get it flattened.
I wrote the function below:
...
1
vote
1
answer
62
views
Depth-first traversal implementation in Java (by recursion)
I implemented a recursive depth-first traversal, with all three traversal modes in this function. Is this the most succinct way to write the code?
...
3
votes
1
answer
3k
views
Java n-ary Tree class with custom made methods and nested Node class
I'm a beginner and I wrote this (working) code for n-ary tree.
The specifics:
Each node is to be built with an integer value.
Each node has a variable number of children.
The nodes should have an ...
1
vote
2
answers
772
views
Find all root to leaf paths in binary tree
Description:
Given a binary tree, return all root-to-leaf paths.
Leetcode
...
2
votes
1
answer
523
views
Find minimum depth in a binary tree
Description:
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
Note: A leaf is a node ...
3
votes
2
answers
1k
views
Algorithm that generate all possible strings from N Tuples. Found Brute Force version, Recursive Version uses a Tree?
I am trying to figure out a solution for a problem. Consider the following tuples (it could be any number of tuples, I am using four in this example):
{A, B, C, D}
...
4
votes
1
answer
524
views
Convert Ternary Expression to a Binary Tree
This is programming question I came across (geeksforgeeks) :
Given a string that contains ternary expressions. The expressions may be nested, task is convert the given ternary expression to a binary ...
1
vote
3
answers
462
views
Exercise - count binary-tree nodes with 1 leaf and 1 internal node as children
I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and am trying to solve one of the exercises there.
The exercise
Write a program that ...
2
votes
0
answers
373
views
Follow-up 1: Compare 2 unordered, rooted trees for shape-isomorphism
The previous post can be found here.
In the previous post I tried to solve an exercise but found through the answer of Peilonrayz a bug in the code and 2 more while fixing it. These have now been ...
3
votes
2
answers
1k
views
Compare 2 unordered, rooted trees for shape-isomorphism
I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and am trying to solve one of the exercises there.
Edit: This question now also has a ...
1
vote
1
answer
2k
views
Recursive Preorder Traversal
For today, I tackled this coding challenge question:
Given a binary tree, write a method to recursively traverse the tree in the preorder manner. Mark a node as visited by adding its data to the list -...
6
votes
1
answer
2k
views
Code smell when recursively returning a List
So this is part of my AVL tree implementation, namely the infix representation of the tree. Since I wanted to use a recursive method to stay close to the original algorithm and want to return a list, ...
5
votes
2
answers
256
views
Binary Search tree deletion optimization
I have just started implementing Binary Search tree on my own without using any tutorials online.
Please have a look and suggest how can I make code less cluttered and more faster. Right now I am ...
6
votes
5
answers
11k
views
DFS in Binary Tree
I have written this code for DFS in a binary tree and would like improvements on it.
...
5
votes
2
answers
1k
views
Algorithm that checks if a tree is full and complete
I am trying to write a method that will return true if a binary tree is full and complete (each node has 2 children or none and all the leaves of the tree are at the same depth).
My idea is to use ...