Skip to content

Instantly share code, notes, and snippets.

View kshirish's full-sized avatar
👨‍💻

k kshirish

👨‍💻
View GitHub Profile
@kshirish
kshirish / bfs.js
Last active August 12, 2024 12:39
Binary Tree (BT)
// Root
// |
// |
// 11 12
// | |
// | |
// 13 14 15 16
// |
// |
// 17 18
@kshirish
kshirish / dfs.js
Last active August 12, 2024 12:40
Binary Tree (BT)
// Root
// |
// |
// 11 12
// | |
// | |
// 13 14 15 16
// |
// |
// 17 18
@kshirish
kshirish / bfs.js
Created August 12, 2024 12:42
N-ary Tree
// Creating a sample n-ary tree
// 1
// / | \
// 2 3 4
// / \ |
// 5 6 7
class NaryTreeNode {
constructor(value) {
this.value = value;
@kshirish
kshirish / dfs.js
Created August 12, 2024 12:44
N-ary Tree
// Creating a sample n-ary tree
// 1
// / | \
// 2 3 4
// / \ |
// 5 6 7
class NaryTreeNode {
constructor(value) {
this.value = value;
@kshirish
kshirish / pre-order.js
Created August 13, 2024 02:44
Binary Tree - A DFS type order
// Root
// |
// |
// 11 12
// | |
// | |
// 13 14 15 16
// |
// |
// 17 18
@kshirish
kshirish / in-order.js
Created August 13, 2024 02:44
Binary Tree - A DFS type order
// Root
// |
// |
// 11 12
// | |
// | |
// 13 14 15 16
// |
// |
// 17 18
@kshirish
kshirish / post-order.js
Created August 13, 2024 02:45
Binary Tree - A DFS type order
// Root
// |
// |
// 11 12
// | |
// | |
// 13 14 15 16
// |
// |
// 17 18
@kshirish
kshirish / bfs.js
Last active August 13, 2024 02:59
Binary Tree Array
// Binary tree represented as an array
// 1
// / \
// 2 3
// / \ \
// 4 5 6
const tree = [1, 2, 3, 4, 5, null, 6];
function bfs(tree) {
@kshirish
kshirish / dfs.js
Created August 13, 2024 02:58
Binary Tree Array
// Binary tree represented as an array
// 1
// / \
// 2 3
// / \ \
// 4 5 6
const tree = [1, 2, 3, 4, 5, null, 6];
function dfs(tree) {
@kshirish
kshirish / getChildrenByNode.js
Created August 13, 2024 03:06
Binary Tree Array - children
// Binary tree represented as an array
// 1
// / \
// 2 3
// / \ \
// 4 5 6
const tree = [1, 2, 3, 4, 5, null, 6];