Skip to main content

All Questions

1 vote
1 answer
86 views

Depth First Search vs Breadth First Search

So after years of teaching myself, I think I'm ready to stand on the shoulders of giants and ask you a good question! I have a tree of nodes. What I want is a function that returns an array of the ...
aName's user avatar
  • 143
4 votes
0 answers
345 views

JavaScript AVL Tree

I have been working through Introduction to Algorithms 3rd Edition, and have implemented an AVL tree through prototypal inheritance. The code presented here does work as expected based on the tests ...
Evan Bechtol's user avatar
  • 1,255
4 votes
1 answer
10k views

Convert nested array of values to a tree structure

I have a nested array that represents a parent child relationship, that I need to convert to a tree structure. Example nested array ...
OrderAndChaos's user avatar
2 votes
1 answer
223 views

Embedding an HTML (String) Generated from a Tree Structured JSON

How to make insertJson faster (I should keep the script compatible with old versions of IE and other browsers)? Problem innerHTML...
Emma's user avatar
  • 3,592
4 votes
0 answers
143 views

All the paths from the root to the leaves

Given a binary tree, return all root-to-leaf paths. Example: -- 1 / \ 2 3 \ 5 Output should be: ["1->2->5", "1->3"] My approach: I walk the branches ...
Rick's user avatar
  • 586
5 votes
1 answer
1k views

Tic Tac Toe game tree generator minimax

I have coded a working Tic Tac Toe game tree generator. It doesn't only generate the game tree, it also applies minimax values to each node. The code works fine on a board that already has 2 or more ...
snowfrogdev's user avatar
3 votes
1 answer
2k views

Return path to a value in a nested object

Description: Its not a programming challenge but I though to write a small utility which will return the path to a primitive value in a possibly nested object. The idea is not original. Code: ...
CodeYogi's user avatar
  • 5,137
4 votes
1 answer
1k views

Calculating binary tree height as asked in the interview

Input: The first line contains the number of vertices \$n\$. The second line contains \$n\$ integer numbers from the range \$\left[−1, n − 1\right]\$ representing the \$0\$-based index of the ...
CodeYogi's user avatar
  • 5,137
1 vote
1 answer
507 views

Construct binary tree from inorder and preorder traversal

...
CodeYogi's user avatar
  • 5,137
1 vote
1 answer
458 views

Kth largest element BST

Would this take \$O(n)\$ in worst case? Can it be improved? ...
CodeYogi's user avatar
  • 5,137
0 votes
1 answer
332 views

Taking a node in rootA and finding a clone node in other tree

I was asked this as an interview question. I was also asked to assume that there is a function which can compare and say two nodes are identical. I would like to implement that function as well. I'm ...
brownmamba's user avatar
2 votes
2 answers
206 views

JavaScript bottom-up tree transformer aimed for performance

...
MaiaVictor's user avatar
  • 1,101