This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Root | |
// | | |
// | | |
// 11 12 | |
// | | | |
// | | | |
// 13 14 15 16 | |
// | | |
// | | |
// 17 18 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Root | |
// | | |
// | | |
// 11 12 | |
// | | | |
// | | | |
// 13 14 15 16 | |
// | | |
// | | |
// 17 18 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating a sample n-ary tree | |
// 1 | |
// / | \ | |
// 2 3 4 | |
// / \ | | |
// 5 6 7 | |
class NaryTreeNode { | |
constructor(value) { | |
this.value = value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating a sample n-ary tree | |
// 1 | |
// / | \ | |
// 2 3 4 | |
// / \ | | |
// 5 6 7 | |
class NaryTreeNode { | |
constructor(value) { | |
this.value = value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Root | |
// | | |
// | | |
// 11 12 | |
// | | | |
// | | | |
// 13 14 15 16 | |
// | | |
// | | |
// 17 18 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Root | |
// | | |
// | | |
// 11 12 | |
// | | | |
// | | | |
// 13 14 15 16 | |
// | | |
// | | |
// 17 18 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Root | |
// | | |
// | | |
// 11 12 | |
// | | | |
// | | | |
// 13 14 15 16 | |
// | | |
// | | |
// 17 18 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Binary tree represented as an array | |
// 1 | |
// / \ | |
// 2 3 | |
// / \ \ | |
// 4 5 6 | |
const tree = [1, 2, 3, 4, 5, null, 6]; | |
function bfs(tree) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Binary tree represented as an array | |
// 1 | |
// / \ | |
// 2 3 | |
// / \ \ | |
// 4 5 6 | |
const tree = [1, 2, 3, 4, 5, null, 6]; | |
function dfs(tree) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Binary tree represented as an array | |
// 1 | |
// / \ | |
// 2 3 | |
// / \ \ | |
// 4 5 6 | |
const tree = [1, 2, 3, 4, 5, null, 6]; | |