From a754d811254d86d326d12eb8ca5633e7a608aba6 Mon Sep 17 00:00:00 2001 From: Ranjeet Kumar Jena Date: Tue, 25 Jul 2023 09:06:24 +0530 Subject: [PATCH 1/5] redundant and duplicate lines fixed --- .../thealgorithms/datastructures/trees/BinaryTree.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/trees/BinaryTree.java b/src/main/java/com/thealgorithms/datastructures/trees/BinaryTree.java index d86130dff470..d699b436d6b9 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/BinaryTree.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/BinaryTree.java @@ -3,7 +3,7 @@ import java.util.LinkedList; import java.util.Queue; -/** +/* * This entire class is used to build a Binary Tree data structure. There is the * Node Class and the Tree Class, both explained below. */ @@ -164,13 +164,11 @@ else if (temp.left != null && temp.right != null) { if (successor.right != null) { successor.right.parent = successor.parent; successor.parent.left = successor.right; - successor.right = temp.right; - successor.right.parent = successor; } else { successor.parent.left = null; - successor.right = temp.right; - successor.right.parent = successor; } + successor.right = temp.right; + successor.right.parent = successor; } if (temp == root) { @@ -304,7 +302,7 @@ public void postOrder(Node localRoot) { */ public void bfs(Node localRoot) { // Create a queue for the order of the nodes - Queue queue = new LinkedList(); + Queue queue = new LinkedList<>(); // If the give root is null, then we don't add to the queue // and won't do anything From be3382f670d60358fee3e4aecc99ea9cabc255c8 Mon Sep 17 00:00:00 2001 From: Ranjeet Kumar Jena Date: Tue, 25 Jul 2023 17:17:03 +0530 Subject: [PATCH 2/5] java convention fixed --- .../datastructures/trees/CheckIfBinaryTreeBalanced.java | 2 +- .../datastructures/trees/CheckTreeIsSymmetric.java | 8 ++++---- .../thealgorithms/datastructures/trees/GenericTree.java | 8 ++++---- .../java/com/thealgorithms/datastructures/trees/LCA.java | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/trees/CheckIfBinaryTreeBalanced.java b/src/main/java/com/thealgorithms/datastructures/trees/CheckIfBinaryTreeBalanced.java index 9dd50245b88e..566536256558 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/CheckIfBinaryTreeBalanced.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/CheckIfBinaryTreeBalanced.java @@ -12,7 +12,7 @@ * `isBalancedRecursive()` is implemented in a recursive fashion, and * `isBalancedIterative()` is implemented in an iterative fashion. * - * @author [Ian Cowan](https://github.com/iccowan) + * @author [Ian Cowan](Git-Ian Cowan) */ public class CheckIfBinaryTreeBalanced { /** diff --git a/src/main/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetric.java b/src/main/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetric.java index 0df93cefb9e3..def455dde051 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetric.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/CheckTreeIsSymmetric.java @@ -39,16 +39,16 @@ public static boolean isSymmetric(Node root) { return isSymmetric(root.left, root.right); } - private static boolean isSymmetric(Node leftSubtreeRoot, Node rightSubtreRoot) { - if (leftSubtreeRoot == null && rightSubtreRoot == null) { + private static boolean isSymmetric(Node leftSubtreeRoot, Node rightSubtreeRoot) { + if (leftSubtreeRoot == null && rightSubtreeRoot == null) { return true; } - if (isInvalidSubtree(leftSubtreeRoot, rightSubtreRoot)) { + if (isInvalidSubtree(leftSubtreeRoot, rightSubtreeRoot)) { return false; } - return isSymmetric(leftSubtreeRoot.right, rightSubtreRoot.left) && isSymmetric(leftSubtreeRoot.left, rightSubtreRoot.right); + return isSymmetric(leftSubtreeRoot.right, rightSubtreeRoot.left) && isSymmetric(leftSubtreeRoot.left, rightSubtreeRoot.right); } private static boolean isInvalidSubtree(Node leftSubtreeRoot, Node rightSubtreeRoot) { diff --git a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java index 25347e2f8b1c..8c30c91b3660 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java @@ -16,24 +16,24 @@ */ public class GenericTree { - private class Node { + private static class Node { int data; ArrayList child = new ArrayList<>(); } - private Node root; + private final Node root; public GenericTree() { // Constructor Scanner scn = new Scanner(System.in); root = create_treeG(null, 0, scn); } - private Node create_treeG(Node node, int childindx, Scanner scn) { + private Node create_treeG(Node node, int childIndx, Scanner scn) { // display if (node == null) { System.out.println("Enter root's data"); } else { - System.out.println("Enter data of parent of index " + node.data + " " + childindx); + System.out.println("Enter data of parent of index " + node.data + " " + childIndx); } // input node = new Node(); diff --git a/src/main/java/com/thealgorithms/datastructures/trees/LCA.java b/src/main/java/com/thealgorithms/datastructures/trees/LCA.java index 26d3a844f7b9..d45f0d4f4301 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/LCA.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/LCA.java @@ -5,7 +5,7 @@ public class LCA { - private static Scanner scanner = new Scanner(System.in); + private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { // The adjacency list representation of a tree: @@ -91,7 +91,7 @@ private static int getLCA(int v1, int v2, int[] depth, int[] parent) { return v1; } } -/** +/* * Input: * 10 * 0 1 From f8bd499505a44e5c2066719759b0b6d8c5125506 Mon Sep 17 00:00:00 2001 From: Ranjeet Kumar Jena Date: Tue, 25 Jul 2023 17:26:31 +0530 Subject: [PATCH 3/5] java convention fixed --- .../thealgorithms/datastructures/trees/BSTIterative.java | 4 ++-- .../thealgorithms/datastructures/trees/BSTRecursive.java | 2 +- .../datastructures/trees/BSTRecursiveGeneric.java | 6 +++--- .../datastructures/trees/CeilInBinarySearchTree.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/trees/BSTIterative.java b/src/main/java/com/thealgorithms/datastructures/trees/BSTIterative.java index db3d0438f4fe..97c2667002b6 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/BSTIterative.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/BSTIterative.java @@ -10,10 +10,10 @@ *

* An implementation of BST iteratively. Binary Search Tree is a binary tree * which satisfies three properties: left child is less than root node, right - * child is grater than root node, both left and right childs must themselves be + * child is grater than root node, both left and right child must themselves be * a BST. * - * @author [Lakhan Nad](https://github.com/Lakhan-Nad) + * @author [Lakhan Nad](git-Lakhan Nad) */ public class BSTIterative { diff --git a/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursive.java b/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursive.java index 34959556a0c3..4e24f4bfb32a 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursive.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursive.java @@ -17,7 +17,7 @@ * I have made public functions as methods and to actually implement recursive * approach I have used private methods * - * @author [Lakhan Nad](https://github.com/Lakhan-Nad) + * @author [Lakhan Nad](git-Lakhan Nad) */ public class BSTRecursive { diff --git a/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursiveGeneric.java b/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursiveGeneric.java index b70fcb280ac3..5c1334ffa0e8 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursiveGeneric.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursiveGeneric.java @@ -9,10 +9,10 @@ *

* A recursive implementation of generic type BST. * - * Reference: https://en.wikipedia.org/wiki/Binary_search_tree + * Reference: Wiki links for BST *

* - * @author [Madhur Panwar](https://github.com/mdrpanwar) + * @author [Madhur Panwar](git-Madhur Panwar) */ public class BSTRecursiveGeneric> { @@ -219,7 +219,7 @@ private void inOrderSort(Node node, List sortedList) { } /** - * Serach recursively if the given value is present in BST or not. + * Search recursively if the given value is present in BST or not. * * @param node the node under which to check * @param data the value to be checked diff --git a/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java b/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java index a6878c75981d..6e1454f6859b 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java @@ -39,7 +39,7 @@ * ii) If key is lesser than root value than ceil will be in right subtree so * call recursively on right subtree iii) if key is greater than current root, * then either a) the root is ceil b) ceil is in left subtree: call for left - * subtree. If left subtree returns a non null value then that will be ceil + * subtree. If left subtree returns a non-null value then that will be ceil * otherwise the root is ceil */ public class CeilInBinarySearchTree { From 39b32a2b2844556e0cda8e1ce9016be584450209 Mon Sep 17 00:00:00 2001 From: Ranjeet Kumar Jena <121615244+RANJEETJ06@users.noreply.github.com> Date: Wed, 26 Jul 2023 19:35:49 +0530 Subject: [PATCH 4/5] Update src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java Yes that would be better Co-authored-by: Andrii Siriak --- .../com/thealgorithms/datastructures/trees/GenericTree.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java index 8c30c91b3660..17d6ce2309dc 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java @@ -28,7 +28,7 @@ public GenericTree() { // Constructor root = create_treeG(null, 0, scn); } - private Node create_treeG(Node node, int childIndx, Scanner scn) { + private Node create_treeG(Node node, int childIndex, Scanner scanner) { // display if (node == null) { System.out.println("Enter root's data"); From 17cac4de25fd48083cce75dae75665ad15fc27c7 Mon Sep 17 00:00:00 2001 From: Andrii Siriak Date: Wed, 26 Jul 2023 18:50:02 +0300 Subject: [PATCH 5/5] Update GenericTree.java --- .../thealgorithms/datastructures/trees/GenericTree.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java index 17d6ce2309dc..d348467815c7 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java @@ -33,15 +33,15 @@ private Node create_treeG(Node node, int childIndex, Scanner scanner) { if (node == null) { System.out.println("Enter root's data"); } else { - System.out.println("Enter data of parent of index " + node.data + " " + childIndx); + System.out.println("Enter data of parent of index " + node.data + " " + childIndex); } // input node = new Node(); - node.data = scn.nextInt(); + node.data = scanner.nextInt(); System.out.println("number of children"); - int number = scn.nextInt(); + int number = scanner.nextInt(); for (int i = 0; i < number; i++) { - Node child = create_treeG(node, i, scn); + Node child = create_treeG(node, i, scanner); node.child.add(child); } return node;