Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Counting Full Nodes in a Binary Tree #415

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="Arrays/1D Arrays"/>
<classpathentry kind="src" path="Arrays/2D Arrays"/>
<classpathentry kind="src" path="Basic Codes"/>
<classpathentry kind="src" path="Bit Manipulation"/>
<classpathentry kind="src" path="CodeChef"/>
<classpathentry kind="src" path="Data Structure/Heap"/>
<classpathentry kind="src" path="Data Structure/Queue/Basic Queue"/>
<classpathentry kind="src" path="Data Structure/Stack"/>
<classpathentry kind="src" path="Data Structure/Trees/Binary Trees"/>
<classpathentry kind="src" path="GeeksForGeeks"/>
<classpathentry kind="src" path="Hackerrank"/>
<classpathentry kind="src" path="LeetCode"/>
<classpathentry kind="src" path="Number Theory"/>
<classpathentry kind="src" path="Pattern_Printing"/>
<classpathentry kind="src" path="Recursion"/>
<classpathentry kind="src" path="Searching"/>
<classpathentry kind="src" path="Sorting"/>
<classpathentry kind="src" path="String Handling"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Java-Questions-and-Solutions</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1633716613659</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"java.project.sourcePaths": [
"Sorting",
"Pattern_Printing",
"Number Theory",
"Basic Codes",
"Pattern_Printing"
"String Handling"
]
}
1 change: 1 addition & 0 deletions Basic Codes/Factorial.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ static int factorialRecursion(int i){

return i*factorialRecursion(i-1);
}

}
2 changes: 1 addition & 1 deletion Basic Codes/RootsOfQuadraticEqn.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//Find the roots of the quadratic Equation
import java.util.Scanner;

public class quadratic_roots {
public class RootsOfQuadraticEqn {

public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
Expand Down
42 changes: 42 additions & 0 deletions Data Structure/Trees/Binary Trees/CountingFullNodes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

//Question: Count all the full nodes(nodes whose left and right children are not null)

//initializing node class
class Node{
int key;
Node left,right;
public Node(int data) {
key=data;
left=right=null;
}
}

public class CountingFullNodes{
Node root;
CountingFullNodes(){
root=null;
}
//recursive function to get the count of full nodes
int getFullCount(Node node) {
if(node==null)
return 0;
int count=0;
if(node.left!=null && node.right!=null)
count++;
count+=(getFullCount(node.left)+getFullCount(node.right));
return count;
}
public static void main(String[] args) {
CountingFullNodes bs=new CountingFullNodes();
bs.root=new Node(1);
bs.root.left = new Node(7);
bs.root.right = new Node(3);
bs.root.left.right = new Node(6);
bs.root.left.right.left = new Node(2);
bs.root.left.right.right = new Node(4);
bs.root.right.right = new Node(9);
bs.root.right.right.left = new Node(11);
bs.root.right.right.right = new Node(10);
System.out.println(bs.getFullCount(bs.root));
}
}
4 changes: 3 additions & 1 deletion Number Theory/ArmstrongNumber.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.util.Scanner;

//Armstrong number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers;
/* 153 = (1*1*1)+(5*5*5)+(3*3*3)
where:
Expand Down Expand Up @@ -29,6 +31,6 @@ public static void main(String[] args) {
} else {
System.out.println(temp + " is not a armstrong number");
}

in.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void main(String[] args) {
//taking user input
int patternHeight = sc.nextInt();

if(height % 2 == 0) {
if(patternHeight % 2 == 0) {
System.out.println("Please specify any odd integer for a better view.");
} else {
printI(patternHeight);
Expand Down
3 changes: 1 addition & 2 deletions Sorting/semisort1.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public static void main(String[] args) throws IOException
{
ar[i]=Integer.parseInt(br.readLine());
}
semisort1 obj= new semisort1(); //Program by LN11211
obj.sort(ar,len,styl);
semisort1.sort(ar,len,styl);
}
}
40 changes: 40 additions & 0 deletions String Handling/isomorphic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


class isomorphic {

static final int CHAR = 26;

static boolean isoMorphic(String str1, String str2)
{
int n = str1.length();
int m = str2.length();

if (n != m)
return false;

// For counting the previous appearances of character in both the strings
int[] countChars1 = new int[CHAR];
int[] countChars2 = new int[CHAR];

for (int i = 0; i < n; i++) {
countChars1[str1.charAt(i) - 'a']++;
countChars2[str2.charAt(i) - 'a']++;

if (countChars1[str1.charAt(i) - 'a']
!= countChars2[str2.charAt(i) - 'a']) {
return false;
}
}
return true;
}


public static void main(String[] args)
{
System.out.println(isoMorphic("aab", "xxy") ? 1
: 0);
System.out.println(isoMorphic("aab", "xyz") ? 1
: 0);
}
}

Empty file added bin/Welcome.txt
Empty file.