From 4096032eba12bb2fdb9e4e926d1742fe85591cac Mon Sep 17 00:00:00 2001
From: Aarzoo Pundir <68347020+aarzoopundir@users.noreply.github.com>
Date: Fri, 8 Oct 2021 16:29:30 +0530
Subject: [PATCH 1/3] checking two strings are isomorphic or not
---
.vscode/settings.json | 3 +-
Basic Codes/Factorial.java | 1 +
Basic Codes/RootsOfQuadraticEqn.java | 2 +-
Number Theory/ArmstrongNumber.java | 4 +-
.../{ => Pattern_Printing}/Letter_T.java | 0
.../{ => pattern_program}/Letter_I.java | 2 +-
Sorting/semisort1.java | 3 +-
String Handling/isomorphic.java | 40 +++++++++++++++++++
8 files changed, 49 insertions(+), 6 deletions(-)
rename Pattern_Printing/{ => Pattern_Printing}/Letter_T.java (100%)
rename Pattern_Printing/{ => pattern_program}/Letter_I.java (97%)
create mode 100644 String Handling/isomorphic.java
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 3f967d9..8818c0f 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,8 +1,9 @@
{
"java.project.sourcePaths": [
"Sorting",
+ "Pattern_Printing",
"Number Theory",
"Basic Codes",
- "Pattern_Printing"
+ "String Handling"
]
}
\ No newline at end of file
diff --git a/Basic Codes/Factorial.java b/Basic Codes/Factorial.java
index 8ee8b78..c061e71 100644
--- a/Basic Codes/Factorial.java
+++ b/Basic Codes/Factorial.java
@@ -16,4 +16,5 @@ static int factorialRecursion(int i){
return i*factorialRecursion(i-1);
}
+
}
\ No newline at end of file
diff --git a/Basic Codes/RootsOfQuadraticEqn.java b/Basic Codes/RootsOfQuadraticEqn.java
index 4b7ace8..68bf3dc 100644
--- a/Basic Codes/RootsOfQuadraticEqn.java
+++ b/Basic Codes/RootsOfQuadraticEqn.java
@@ -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);
diff --git a/Number Theory/ArmstrongNumber.java b/Number Theory/ArmstrongNumber.java
index 5b2ea90..2424ba6 100644
--- a/Number Theory/ArmstrongNumber.java
+++ b/Number Theory/ArmstrongNumber.java
@@ -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:
@@ -29,6 +31,6 @@ public static void main(String[] args) {
} else {
System.out.println(temp + " is not a armstrong number");
}
-
+ in.close();
}
}
diff --git a/Pattern_Printing/Letter_T.java b/Pattern_Printing/Pattern_Printing/Letter_T.java
similarity index 100%
rename from Pattern_Printing/Letter_T.java
rename to Pattern_Printing/Pattern_Printing/Letter_T.java
diff --git a/Pattern_Printing/Letter_I.java b/Pattern_Printing/pattern_program/Letter_I.java
similarity index 97%
rename from Pattern_Printing/Letter_I.java
rename to Pattern_Printing/pattern_program/Letter_I.java
index ecb5b48..5cc9a6e 100644
--- a/Pattern_Printing/Letter_I.java
+++ b/Pattern_Printing/pattern_program/Letter_I.java
@@ -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);
diff --git a/Sorting/semisort1.java b/Sorting/semisort1.java
index 76742a7..4bcd1f8 100644
--- a/Sorting/semisort1.java
+++ b/Sorting/semisort1.java
@@ -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);
}
}
\ No newline at end of file
diff --git a/String Handling/isomorphic.java b/String Handling/isomorphic.java
new file mode 100644
index 0000000..235f866
--- /dev/null
+++ b/String Handling/isomorphic.java
@@ -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);
+ }
+}
+
\ No newline at end of file
From 3bf31fdf40fc394097e673093f8fd15a805ffdf3 Mon Sep 17 00:00:00 2001
From: Aarzoo Pundir <68347020+aarzoopundir@users.noreply.github.com>
Date: Sat, 9 Oct 2021 12:22:16 +0530
Subject: [PATCH 2/3] CountingFullNodes
---
.classpath | 23 +++++++++++
.project | 28 +++++++++++++
Arrays/1D Arrays/CountFullNodes.java | 4 ++
.../Trees/Binary Trees/CountFullNodes.java | 41 +++++++++++++++++++
bin/Welcome.txt | 0
5 files changed, 96 insertions(+)
create mode 100644 .classpath
create mode 100644 .project
create mode 100644 Arrays/1D Arrays/CountFullNodes.java
create mode 100644 Data Structure/Trees/Binary Trees/CountFullNodes.java
create mode 100644 bin/Welcome.txt
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..0e5c983
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..d8c5dc8
--- /dev/null
+++ b/.project
@@ -0,0 +1,28 @@
+
+
+ Java-Questions-and-Solutions
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
+
+ 1633716613659
+
+ 30
+
+ org.eclipse.core.resources.regexFilterMatcher
+ node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
+
+
+
+
diff --git a/Arrays/1D Arrays/CountFullNodes.java b/Arrays/1D Arrays/CountFullNodes.java
new file mode 100644
index 0000000..800a003
--- /dev/null
+++ b/Arrays/1D Arrays/CountFullNodes.java
@@ -0,0 +1,4 @@
+
+public class CountFullNodes {
+
+}
diff --git a/Data Structure/Trees/Binary Trees/CountFullNodes.java b/Data Structure/Trees/Binary Trees/CountFullNodes.java
new file mode 100644
index 0000000..a25b0f4
--- /dev/null
+++ b/Data Structure/Trees/Binary Trees/CountFullNodes.java
@@ -0,0 +1,41 @@
+//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 CountFullNodes{
+ Node root;
+ CountFullNodes(){
+ 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) {
+ CountFullNodes bs=new CountFullNodes();
+ 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));
+ }
+}
diff --git a/bin/Welcome.txt b/bin/Welcome.txt
new file mode 100644
index 0000000..e69de29
From cc1d50eafb2cb40030d1f5c4f6b8f63034d98b0b Mon Sep 17 00:00:00 2001
From: Aarzoo Pundir <68347020+aarzoopundir@users.noreply.github.com>
Date: Wed, 13 Oct 2021 09:38:25 +0530
Subject: [PATCH 3/3] Counting Full Nodes in a binary tree
---
Arrays/1D Arrays/CountFullNodes.java | 4 ----
.../{CountFullNodes.java => CountingFullNodes.java} | 7 ++++---
2 files changed, 4 insertions(+), 7 deletions(-)
delete mode 100644 Arrays/1D Arrays/CountFullNodes.java
rename Data Structure/Trees/Binary Trees/{CountFullNodes.java => CountingFullNodes.java} (90%)
diff --git a/Arrays/1D Arrays/CountFullNodes.java b/Arrays/1D Arrays/CountFullNodes.java
deleted file mode 100644
index 800a003..0000000
--- a/Arrays/1D Arrays/CountFullNodes.java
+++ /dev/null
@@ -1,4 +0,0 @@
-
-public class CountFullNodes {
-
-}
diff --git a/Data Structure/Trees/Binary Trees/CountFullNodes.java b/Data Structure/Trees/Binary Trees/CountingFullNodes.java
similarity index 90%
rename from Data Structure/Trees/Binary Trees/CountFullNodes.java
rename to Data Structure/Trees/Binary Trees/CountingFullNodes.java
index a25b0f4..2d0717d 100644
--- a/Data Structure/Trees/Binary Trees/CountFullNodes.java
+++ b/Data Structure/Trees/Binary Trees/CountingFullNodes.java
@@ -1,3 +1,4 @@
+
//Question: Count all the full nodes(nodes whose left and right children are not null)
//initializing node class
@@ -10,9 +11,9 @@ public Node(int data) {
}
}
-public class CountFullNodes{
+public class CountingFullNodes{
Node root;
- CountFullNodes(){
+ CountingFullNodes(){
root=null;
}
//recursive function to get the count of full nodes
@@ -26,7 +27,7 @@ int getFullCount(Node node) {
return count;
}
public static void main(String[] args) {
- CountFullNodes bs=new CountFullNodes();
+ CountingFullNodes bs=new CountingFullNodes();
bs.root=new Node(1);
bs.root.left = new Node(7);
bs.root.right = new Node(3);