Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling latest changes #1

Merged
merged 28 commits into from
Oct 11, 2019
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dbfe9f1
return list instead of console.log
maharshi-gor Oct 8, 2019
7cfb06f
Adds testing for the get mazePath problem #48
glennforrest Oct 8, 2019
d153c6c
Add unit tests to postfix expression evaluation function. Resolves #34
Oct 9, 2019
9e07a94
Merge pull request #52 from Mk996/master
ashokdey Oct 9, 2019
5c826c5
Merge pull request #59 from vobango/master
TheSTL Oct 10, 2019
19222fb
Merge pull request #53 from glennforrest/adds-tests-for-get-mazePath
TheSTL Oct 10, 2019
05184c4
update: find k-th max in BST
ashokdey Oct 10, 2019
4a75147
update: entry in readme
ashokdey Oct 10, 2019
93af26e
Merge branch 'master' of github.com:knaxus/problem-solving-javascript…
ashokdey Oct 10, 2019
f376135
fix: closing of `<sup>`
ashokdey Oct 10, 2019
0ff8d47
fix: typo error
ashokdey Oct 10, 2019
0bf9860
update: find kth min & throw error for invalid K
ashokdey Oct 10, 2019
4980e96
Merge branch 'problems' of github.com:knaxus/problem-solving-javascri…
ashokdey Oct 10, 2019
ca93db3
update: entry in README & folder rename
ashokdey Oct 10, 2019
b4507f1
update: rename folder and fix condition for K
ashokdey Oct 10, 2019
ab8b038
update: fix entries in readme
ashokdey Oct 10, 2019
81c88b8
update: find all ancestors of a node
ashokdey Oct 10, 2019
252e912
update: entry in README
ashokdey Oct 10, 2019
c9e3a6a
update: reverse order of pushing nodes
ashokdey Oct 10, 2019
c4a733a
update: height of BST
ashokdey Oct 10, 2019
c95821c
update: entry in README
ashokdey Oct 10, 2019
a75e950
update: Find k nodes from the root
ashokdey Oct 10, 2019
6416cfc
update: entry in README
ashokdey Oct 10, 2019
bfbee74
Merge pull request #62 from knaxus/problems
TheSTL Oct 10, 2019
597cd0e
Fix Fibonacci problem for negative numbers (#55)
SumeetHaryani Oct 10, 2019
97f8f94
fix: change in code, return null when node not found
ashokdey Oct 11, 2019
28e73b5
update: fix the edge case using array approach
ashokdey Oct 11, 2019
e78eae5
Merge pull request #63 from knaxus/trees
ashokdey Oct 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update: height of BST
  • Loading branch information
ashokdey committed Oct 10, 2019
commit c4a733a5198816e922bf6845df8b2ede8a52d00f
35 changes: 35 additions & 0 deletions src/_DataStructures_/Trees/BinarySearchTree/height-of-bst/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// eslint-disable-next-line no-unused-vars
const BST = require('../index');

function findHeightOfBST(root) {
let leftHeight = 0;
let rightHeight = 0;

if (root === null) return 0;
leftHeight = findHeightOfBST(root.leftChild);
rightHeight = findHeightOfBST(root.rightChild);

if (leftHeight > rightHeight) {
return leftHeight + 1;
}
return rightHeight + 1;
}

// create a BST
// const myBST = new BST(6);
// myBST.add(4);
// myBST.add(9);
// myBST.add(2);
// myBST.add(5);
// myBST.add(14);
// myBST.add(8);
// myBST.add(12);
// myBST.add(10);

// // find 3rd max
// // console.log(myBST.root);
// console.log(myBST.traversePreorder());
// // console.log(myBST.root.rightChild);
// console.log(findHeightOfBST(myBST.root));

module.exports = findHeightOfBST;