In a quiz for my Javascript class, we were told to make a simple tree and write a function that returns true or false whether it is a BST or not.  I got a decent grade, but i got 10 points off because the instructor said "It can be done in 6 less...
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 just finished my first binary search tree remove function and it is in major need of optimization. I have spent a lot of time on this and this was the best I could manage. Is there a easier way to do this? Does anyone have any suggestions for optim...
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...
There's a binary search tree, where all nodes to the left are smaller, and all nodes to the right are greater.  I'm trying to create a function isPresent that will check if value is present in the BST. If yes, it returns 1. If no, it returns...
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...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.