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 am working on a Binary search tree and have a problem while adding the values to the tree. When I add values(numbers) in order (descending or ascending) they are added in the right positions, but if I add value that is supposed to go somewhere in b...

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...

I have the following function for calculating coordinates for every node in a binary tree. //x & y parameters should be untouched //root assumed to be 0,0 function nodeCoordinates(node, x, y) { if (x === undefined && y === undefined...

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...

©2020 All rights reserved.