I'm trying to understand how to create objects in js using prototypal inheritance i.e using Object.create() instead of the new keyword. I created a node class for the purposes of making a tree data structure using the implementation below:  Objec...
So I created an implicit binary tree, and a simple way of navigating through that tree that reacts when, for example, you push the left arrow, right arrow, or up arrow:  var items = [ .... ];  function newItem() {     var me = this;     this.item_loc...
I came across this problem online and I wrote the following function to check if a BST is valid. However, what I don't fully understand is how max/min change from null to values that you can compare against.  so in the following function:  //Give...
I try to create a BST with the following code, nums = [4,5,8,2]  var TreeNode = function (val) {     this.val = val;     this.left = this.right = null;     this.count = 1; }  var constructBST = function(nums) {     if (nums.length === 0) return null;...
My problem is really simple. I'm trying to remove a node from my tree with the following structure. How could I delete the node that meets my condition? Basically I just want to set it to null so its parent just points to null.  This is not the a...
The question is, given a BST, find out whether there are two numbers that add up to a given number k. No extra memory should be used.  Now if it were a sorted array, I could have simply kept two pointers, one at the beginning, one at the end. At each...
I have built a VR application similar to WebVR-Vive-Dragging that allows to interact with numerous 3d objects using VR controllers. This means that a user can grab an object with a VR controller and can move or scale it.   In my application, a collis...
Problem: given a binary search tree, print out the longest path.   Approach: Store the possible depths at each level and filter out the longest one. The time complexity of this must be at least O(n) because we are calculating the diameter of the tree...
I'm building a non ordered binary tree that looks like this                                    1                                  /   \                                30     2                                  \   / \...
I've been trying to get the test cases on OJ Leetcode to pass for validating a BST using level order traversal and it's not passing. I'm passing 73/74 and can't figure out why. Any advice to point me in the correct direction is much a...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.