Skip to content

Instantly share code, notes, and snippets.

View kshirish's full-sized avatar
👨‍💻

k kshirish

👨‍💻
View GitHub Profile
@kshirish
kshirish / binaryTree.js
Created August 13, 2024 03:44
Binary Tree Node - Insert, Delete
// Root
// |
// |
// 11 12
// | |
// | |
// 13 14 15 16
// |
// |
// 17 18
@kshirish
kshirish / binaryTree.js
Created August 13, 2024 03:54
Binary Tree Array - Insert, Delete
function insert(tree, value) {
tree.push(value);
return tree;
}
function deleteNode(tree, value) {
const index = tree.indexOf(value);
if (index === -1) {
return tree;
@kshirish
kshirish / binarySearchTree.js
Created August 13, 2024 04:07
Binary Search Tree - Insert, Delete
class TreeNode {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
constructor() {
@kshirish
kshirish / inverseBinaryTree.js
Created August 14, 2024 06:45
Binary Tree - inverse (mirror)
// Example 1:
// Input: root = [4,2,7,1,3,6,9]
// Output: [4,7,2,9,6,3,1]
// Example 2:
// Input: root = [4,2,7,1,3,6]
// Output: [4,7,2,6,3,1]
// Example 3:
// Input: root = [2,1,3]