TreeOperations
This is implementation of operations on a Tree
Method Summary
Public Methods | ||
public |
Given a binary tree, find height of it. |
|
public |
levelOrder(node: TreeNode) You are given a tree and you need to do the level order traversal on this tree. |
|
public |
levelOrderByLine(node: TreeNode) Given a Binary Tree, your task is to print its level order traversal such that each level is separated by $. |
|
public |
printGivenLevel(node: TreeNode, level: number, ltr: boolean) |
|
public |
Complete the function to print spiral order traversal of a tree. |
Public Methods
public height(node: undefined): number source
Given a binary tree, find height of it.
1 / \ 10 39 / 5
Params:
Name | Type | Attribute | Description |
node | undefined |
public levelOrder(node: TreeNode) source
You are given a tree and you need to do the level order traversal on this tree. Level order traversal of a tree is breadth-first traversal for the tree. Testcase1: The tree is 1 / \ 3 2 So, the level order would be 1 3 2 Testcase2: The tree is 10 / \ 20 30 / \ 40 60 So, the level order would be 10 20 30 40 60
Params:
Name | Type | Attribute | Description |
node | TreeNode |
public levelOrderByLine(node: TreeNode) source
Given a Binary Tree, your task is to print its level order traversal such that each level is separated by $. For the below tree the output will be 1 $ 2 3 $ 4 5 6 7 $ 8 $. 1 / \ 2 3 / \ / \ 4 5 6 7 \ 8
Params:
Name | Type | Attribute | Description |
node | TreeNode |
public spiral(node: TreeNode) source
Complete the function to print spiral order traversal of a tree. Testcase1: The tree is 1 / \ 3 2 So, the spiral level order would be 1 3 2 Testcase2: The tree is 10 / \ 20 30 / \ 40 60 / \ 50 55 70 80 So, the spiral level order would be 10 20 30 60 40
Params:
Name | Type | Attribute | Description |
node | TreeNode |