Skip to content

Commit cf24dd9

Browse files
Add files via upload
1 parent d6e05fc commit cf24dd9

File tree

7 files changed

+123
-0
lines changed

7 files changed

+123
-0
lines changed

BINARY TREE 1/HEIGHT OF TREE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Solution {
2+
3+
public static int height(BinaryTreeNode<Integer> root) {
4+
//Your code goes here
5+
if (root==null)
6+
{
7+
return 0;
8+
}
9+
10+
int smallLeftOutput=height(root.left);
11+
int smallRightOutput=height(root.right);
12+
if (smallLeftOutput>smallRightOutput)
13+
{
14+
return smallLeftOutput+1;
15+
}
16+
else
17+
{
18+
return smallRightOutput+1;
19+
}
20+
}
21+
22+
}

BINARY TREE 1/IS NODE PRESENT.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Solution {
2+
3+
public static boolean isNodePresent(BinaryTreeNode<Integer> root, int x) {
4+
//Your code goes here
5+
if (root==null)
6+
{
7+
return false;
8+
}
9+
10+
if (root.data==x)
11+
{
12+
return true;
13+
}
14+
else
15+
{
16+
return (isNodePresent(root.left,x)||isNodePresent(root.right,x));
17+
}
18+
}
19+
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class Solution {
2+
3+
public static int countNodesGreaterThanX(BinaryTreeNode<Integer> root, int x) {
4+
//Your code goes here
5+
if (root==null)
6+
{
7+
return 0;
8+
}
9+
10+
int smallOutput=countNodesGreaterThanX(root.left,x)+countNodesGreaterThanX(root.right,x);
11+
if (root.data>x)
12+
{
13+
return smallOutput+1;
14+
}
15+
else
16+
{
17+
return smallOutput;
18+
}
19+
}
20+
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Solution {
2+
3+
public static void postOrder(BinaryTreeNode<Integer> root) {
4+
//Your code goes here
5+
if (root==null)
6+
{
7+
return;
8+
}
9+
postOrder(root.left);
10+
postOrder(root.right);
11+
System.out.print(root.data+" ");
12+
}
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Solution {
2+
3+
public static void preOrder(BinaryTreeNode<Integer> root) {
4+
//Your code goes here
5+
if (root==null)
6+
{
7+
return;
8+
}
9+
System.out.print(root.data+" ");
10+
preOrder(root.left);
11+
preOrder(root.right);
12+
}
13+
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Solution {
2+
3+
public static void changeToDepthTree(BinaryTreeNode<Integer> root) {
4+
//Your code goes here
5+
changeToDepthTree(root,0);
6+
}
7+
8+
public static void changeToDepthTree(BinaryTreeNode<Integer> root, int depth)
9+
{
10+
if (root==null)
11+
{
12+
return;
13+
}
14+
root.data=depth;
15+
changeToDepthTree(root.left,depth+1);
16+
changeToDepthTree(root.right,depth+1);
17+
}
18+
19+
}

BINARY TREE 1/SUM OF NODES.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Solution {
2+
3+
public static int getSum(BinaryTreeNode<Integer> root) {
4+
//Your code goes here.
5+
if (root==null)
6+
{
7+
return 0;
8+
}
9+
int smallSum=getSum(root.left)+getSum(root.right);
10+
return root.data+smallSum;
11+
}
12+
13+
}

0 commit comments

Comments
 (0)