diff --git a/checkstyle.xml b/checkstyle.xml
index 45431b39897a..af5e3527e32f 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -99,7 +99,7 @@
-
+
diff --git a/src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java b/src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java
index a21f8c05f292..6f93b704ffb2 100644
--- a/src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java
+++ b/src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java
@@ -1,16 +1,14 @@
-/**
- * Author : Siddhant Swarup Mallick
- * Github : https://github.com/siddhant2002
- */
-
-/** Program description - To find all possible paths from source to destination*/
-
-/**Wikipedia link -> https://en.wikipedia.org/wiki/Shortest_path_problem */
package com.thealgorithms.backtracking;
import java.util.ArrayList;
import java.util.List;
+/**
+ * Program description - To find all possible paths from source to destination
+ * Wikipedia
+ *
+ * @author Siddhant Swarup Mallick
+ */
public class AllPathsFromSourceToTarget {
// No. of vertices in graph
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java b/src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java
index 65483eeeb65c..f12e3892b1b2 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java
@@ -2,9 +2,9 @@
/**
* Java program for Hamiltonian Cycle
- * (https://en.wikipedia.org/wiki/Hamiltonian_path)
+ * wikipedia
*
- * @author Akshay Dubey (https://github.com/itsAkshayDubey)
+ * @author Akshay Dubey
*/
public class HamiltonianCycle {
@@ -58,31 +58,31 @@ public boolean isPathFound(int vertex) {
return true;
}
- /** all vertices selected but last vertex not linked to 0 **/
+ /* all vertices selected but last vertex not linked to 0 **/
if (this.pathCount == this.vertex) {
return false;
}
for (int v = 0; v < this.vertex; v++) {
- /** if connected **/
+ /* if connected **/
if (this.graph[vertex][v] == 1) {
- /** add to path **/
+ /* add to path **/
this.cycle[this.pathCount++] = v;
- /** remove connection **/
+ /* remove connection **/
this.graph[vertex][v] = 0;
this.graph[v][vertex] = 0;
- /** if vertex not already selected solve recursively **/
+ /* if vertex not already selected solve recursively **/
if (!isPresent(v)) {
return isPathFound(v);
}
- /** restore connection **/
+ /* restore connection **/
this.graph[vertex][v] = 1;
this.graph[v][vertex] = 1;
- /** remove path **/
+ /* remove path **/
this.cycle[--this.pathCount] = -1;
}
}
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java b/src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java
index be83ea32f496..d5035cf625a6 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java
@@ -8,9 +8,6 @@
import java.util.Queue;
import java.util.Set;
-/**
- * An algorithm that sorts a graph in toplogical order.
- */
/**
* A class that represents the adjaceny list of a graph
*/
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/Kosaraju.java b/src/main/java/com/thealgorithms/datastructures/graphs/Kosaraju.java
index 7c0c0b2bee78..c5f15839f997 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/Kosaraju.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/Kosaraju.java
@@ -6,53 +6,50 @@
/**
* Java program that implements Kosaraju Algorithm.
- * @author Shivanagouda S A (https://github.com/shivu2002a)
- *
- */
-
-/**
+ * @author Shivanagouda S A
+ *
* Kosaraju algorithm is a linear time algorithm to find the strongly connected components of a
- directed graph, which, from here onwards will be referred by SCC. It leverages the fact that the
- transpose graph (same graph with all the edges reversed) has exactly the same SCCs as the original
- graph.
+directed graph, which, from here onwards will be referred by SCC. It leverages the fact that the
+transpose graph (same graph with all the edges reversed) has exactly the same SCCs as the original
+graph.
* A graph is said to be strongly connected if every vertex is reachable from every other vertex.
- The SCCs of a directed graph form a partition into subgraphs that are themselves strongly
- connected. Single node is always a SCC.
+The SCCs of a directed graph form a partition into subgraphs that are themselves strongly
+connected. Single node is always a SCC.
* Example:
- 0 <--- 2 -------> 3 -------- > 4 ---- > 7
- | ^ | ^ ^
- | / | \ /
- | / | \ /
- v / v \ /
- 1 5 --> 6
+0 <--- 2 -------> 3 -------- > 4 ---- > 7
+| ^ | ^ ^
+| / | \ /
+| / | \ /
+v / v \ /
+1 5 --> 6
- For the above graph, the SCC list goes as follows:
- 0, 1, 2
- 3
- 4, 5, 6
- 7
+For the above graph, the SCC list goes as follows:
+0, 1, 2
+3
+4, 5, 6
+7
- We can also see that order of the nodes in an SCC doesn't matter since they are in cycle.
+We can also see that order of the nodes in an SCC doesn't matter since they are in cycle.
- {@summary}
+{@summary}
* Kosaraju Algorithm:
- 1. Perform DFS traversal of the graph. Push node to stack before returning. This gives edges
- sorted by lowest finish time.
- 2. Find the transpose graph by reversing the edges.
- 3. Pop nodes one by one from the stack and again to DFS on the modified graph.
-
- The transpose graph of the above graph:
- 0 ---> 2 <------- 3 <------- 4 <------ 7
- ^ / ^ \ /
- | / | \ /
- | / | \ /
- | v | v v
- 1 5 <--- 6
-
- We can observe that this graph has the same SCC as that of original graph.
+1. Perform DFS traversal of the graph. Push node to stack before returning. This gives edges
+sorted by lowest finish time.
+2. Find the transpose graph by reversing the edges.
+3. Pop nodes one by one from the stack and again to DFS on the modified graph.
+
+The transpose graph of the above graph:
+0 ---> 2 <------- 3 <------- 4 <------ 7
+^ / ^ \ /
+| / | \ /
+| / | \ /
+| v | v v
+1 5 <--- 6
+
+We can observe that this graph has the same SCC as that of original graph.
*/
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java b/src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java
index 336e375f7d4e..de50044256c6 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java
@@ -6,51 +6,48 @@
/**
* Java program that implements Tarjan's Algorithm.
- * @author Shivanagouda S A (https://github.com/shivu2002a)
- *
- */
-
-/**
+ * @author Shivanagouda S A
+ *
* Tarjan's algorithm is a linear time algorithm to find the strongly connected components of a
- directed graph, which, from here onwards will be referred as SCC.
+directed graph, which, from here onwards will be referred as SCC.
* A graph is said to be strongly connected if every vertex is reachable from every other vertex.
- The SCCs of a directed graph form a partition into subgraphs that are themselves strongly
- connected. Single node is always a SCC.
+The SCCs of a directed graph form a partition into subgraphs that are themselves strongly
+connected. Single node is always a SCC.
* Example:
- 0 --------> 1 -------> 3 --------> 4
- ^ /
- | /
- | /
- | /
- | /
- | /
- | /
- | /
- | /
- | /
- |V
- 2
-
- For the above graph, the SCC list goes as follows:
- 1, 2, 0
- 3
- 4
-
- We can also see that order of the nodes in an SCC doesn't matter since they are in cycle.
-
- {@summary}
- Tarjan's Algorithm:
- * DFS search produces a DFS tree
- * Strongly Connected Components form subtrees of the DFS tree.
- * If we can find the head of these subtrees, we can get all the nodes in that subtree (including
- the head) and that will be one SCC.
- * There is no back edge from one SCC to another (here can be cross edges, but they will not be
- used).
-
- * Kosaraju Algorithm aims at doing the same but uses two DFS traversalse whereas Tarjan’s
- algorithm does the same in a single DFS, which leads to much lower constant factors in the latter.
+0 --------> 1 -------> 3 --------> 4
+^ /
+| /
+| /
+| /
+| /
+| /
+| /
+| /
+| /
+| /
+|V
+2
+
+For the above graph, the SCC list goes as follows:
+1, 2, 0
+3
+4
+
+We can also see that order of the nodes in an SCC doesn't matter since they are in cycle.
+
+{@summary}
+Tarjan's Algorithm:
+ * DFS search produces a DFS tree
+ * Strongly Connected Components form subtrees of the DFS tree.
+ * If we can find the head of these subtrees, we can get all the nodes in that subtree (including
+the head) and that will be one SCC.
+ * There is no back edge from one SCC to another (here can be cross edges, but they will not be
+used).
+
+ * Kosaraju Algorithm aims at doing the same but uses two DFS traversalse whereas Tarjan’s
+algorithm does the same in a single DFS, which leads to much lower constant factors in the latter.
*/
public class TarjansAlgorithm {
@@ -58,7 +55,7 @@ public class TarjansAlgorithm {
// Timer for tracking lowtime and insertion time
private int time;
- private List> sccList = new ArrayList>();
+ private final List> sccList = new ArrayList>();
public List> stronglyConnectedComponents(int v, List> graph) {
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/RandomNode.java b/src/main/java/com/thealgorithms/datastructures/lists/RandomNode.java
index 7318b8027f8c..dac88dd9f241 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/RandomNode.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/RandomNode.java
@@ -1,43 +1,37 @@
-/**
- * Author : Suraj Kumar
- * Github : https://github.com/skmodi649
- */
+package com.thealgorithms.datastructures.lists;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
/**
+ * @author Suraj Kumar
+ *
* PROBLEM DESCRIPTION :
* There is a single linked list and we are supposed to find a random node in the given linked list
- */
-
-/**
+ *
* ALGORITHM :
* Step 1 : START
* Step 2 : Create an arraylist of type integer
* Step 3 : Declare an integer type variable for size and linked list type for head
* Step 4 : We will use two methods, one for traversing through the linked list using while loop and
* also increase the size by 1
- *
+ *
* (a) RandomNode(head)
* (b) run a while loop till null;
* (c) add the value to arraylist;
* (d) increase the size;
- *
+ *
* Step 5 : Now use another method for getting random values using Math.random() and return the
* value present in arraylist for the calculated index Step 6 : Now in main() method we will simply
* insert nodes in the linked list and then call the appropriate method and then print the random
* node generated Step 7 : STOP
*/
-
-package com.thealgorithms.datastructures.lists;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
public class RandomNode {
- private List list;
+ private final List list;
private int size;
- private static Random rand = new Random();
+ private static final Random RAND = new Random();
static class ListNode {
@@ -63,10 +57,23 @@ public RandomNode(ListNode head) {
}
public int getRandom() {
- int index = rand.nextInt(size);
+ int index = RAND.nextInt(size);
return list.get(index);
}
+ /**
+ * OUTPUT :
+ * First output :
+ * Random Node : 25
+ * Second output :
+ * Random Node : 78
+ * Time Complexity : O(n)
+ * Auxiliary Space Complexity : O(1)
+ * Time Complexity : O(n)
+ * Auxiliary Space Complexity : O(1)
+ * Time Complexity : O(n)
+ * Auxiliary Space Complexity : O(1)
+ */
// Driver program to test above functions
public static void main(String[] args) {
ListNode head = new ListNode(15);
@@ -80,18 +87,3 @@ public static void main(String[] args) {
System.out.println("Random Node : " + randomNum);
}
}
-/**
- * OUTPUT :
- * First output :
- * Random Node : 25
- * Second output :
- * Random Node : 78
- * Time Complexity : O(n)
- * Auxiliary Space Complexity : O(1)
- * Time Complexity : O(n)
- * Auxiliary Space Complexity : O(1)
- */
-/**
- * Time Complexity : O(n)
- * Auxiliary Space Complexity : O(1)
- */
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
index bca3c77f2724..d5d3f31f4b66 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
@@ -5,7 +5,7 @@
import java.util.StringJoiner;
/**
- * https://en.wikipedia.org/wiki/Linked_list
+ * wikipedia
*/
public class SinglyLinkedList implements Iterable {
@@ -95,7 +95,7 @@ public void swapNodes(int valueFirst, int valueSecond) {
previousB = currentB;
currentB = currentB.next;
}
- /** If either of 'a' or 'b' is not present, then return */
+ /* If either of 'a' or 'b' is not present, then return */
if (currentA == null || currentB == null) {
return;
}
@@ -334,11 +334,6 @@ public void insertNth(int data, int position) {
size++;
}
- /**
- * Swaps nodes of two given values a and b.
- *
- */
-
/**
* Deletes a node at the head
*/
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java b/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java
index f238b5e9fe8d..214e111b9f1a 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/CeilInBinarySearchTree.java
@@ -18,8 +18,6 @@
*
* Ex.2. [30,20,40,10,25,35,50] represents level order traversal of a binary
* search tree. Find ceil for 52 Answer: -1
- */
-/**
*
* Solution 1: Brute Force Solution: Do an inorder traversal and save result
* into an array. Iterate over the array to get an element equal to or greater
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java
index 79c66cb90f01..d166653ff1b4 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java
@@ -1,12 +1,12 @@
package com.thealgorithms.datastructures.trees;
+import java.util.Scanner;
+
/**
* Trie Data structure implementation without any libraries
*
- * @author Dheeraj Kumar Barnwal (https://github.com/dheeraj92)
+ * @author Dheeraj Kumar Barnwal
*/
-import java.util.Scanner;
-
public class TrieImp {
public class TrieNode {
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java b/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java
index 8658bca3df52..d01066f611bd 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/CatalanNumber.java
@@ -1,15 +1,14 @@
package com.thealgorithms.dynamicprogramming;
+import java.util.Scanner;
/**
* This file contains an implementation of finding the nth CATALAN NUMBER using
- * dynamic programming Wikipedia: https://en.wikipedia.org/wiki/Catalan_number
+ * dynamic programming : Wikipedia
*
* Time Complexity: O(n^2) Space Complexity: O(n)
*
- * @author AMRITESH ANAND (https://github.com/amritesh19)
+ * @author AMRITESH ANAND
*/
-import java.util.Scanner;
-
public final class CatalanNumber {
private CatalanNumber() {
}
@@ -31,7 +30,7 @@ static long findNthCatalan(int n) {
catalanArray[0] = 1;
catalanArray[1] = 1;
- /**
+ /*
* The Catalan numbers satisfy the recurrence relation C₀=1 and Cn = Σ
* (Ci * Cn-1-i), i = 0 to n-1 , n > 0
*/
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/CountFriendsPairing.java b/src/main/java/com/thealgorithms/dynamicprogramming/CountFriendsPairing.java
index 8c70c9c3fada..e731524d4958 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/CountFriendsPairing.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/CountFriendsPairing.java
@@ -1,20 +1,14 @@
+package com.thealgorithms.dynamicprogramming;
+
/**
- * Author : Siddhant Swarup Mallick
- * Github : https://github.com/siddhant2002
- */
-/**
+ * @author Siddhant Swarup Mallick
+
* In mathematics, the Golomb sequence is a non-decreasing integer sequence where n-th term is equal
* to number of times n appears in the sequence.
- */
-/**
- * Wikipedia Link - https://en.wikipedia.org/wiki/Golomb_sequence
+ * Wikipedia
+ * Program description - To find the Golomb sequence upto n
*/
-
-/** Program description - To find the Golomb sequence upto n */
-
-package com.thealgorithms.dynamicprogramming;
-
public final class CountFriendsPairing {
private CountFriendsPairing() {
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java b/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java
index 6db30514db68..55ce50d30ea4 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java
@@ -1,5 +1,6 @@
package com.thealgorithms.dynamicprogramming;
+import java.util.Scanner;
/**
* A DynamicProgramming based solution for Edit Distance problem In Java
* Description of Edit Distance with an Example:
@@ -22,8 +23,6 @@
*
* @author SUBHAM SANGHAI
*/
-import java.util.Scanner;
-
public final class EditDistance {
private EditDistance() {
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java b/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
index 9962cca217a0..905815d10a29 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
@@ -1,15 +1,20 @@
-/**
- * Author : Siddhant Swarup Mallick
- * Github : https://github.com/siddhant2002
- */
-
-/** Program description - To find the maximum subarray sum */
package com.thealgorithms.dynamicprogramming;
+/**
+ * @author Siddhant Swarup Mallick
+ * Program description - To find the maximum subarray sum
+ */
public final class KadaneAlgorithm {
private KadaneAlgorithm() {
}
+ /**
+ * OUTPUT :
+ * Input - {89,56,98,123,26,75,12,40,39,68,91}
+ * Output: it returns either true or false
+ * 1st approach Time Complexity : O(n)
+ * Auxiliary Space Complexity : O(1)
+ */
public static boolean maxSum(int[] a, int predictedAnswer) {
int sum = a[0];
int runningSum = 0;
@@ -28,11 +33,4 @@ public static boolean maxSum(int[] a, int predictedAnswer) {
// It returns true if sum and predicted answer matches
// The predicted answer is the answer itself. So it always return true
}
- /**
- * OUTPUT :
- * Input - {89,56,98,123,26,75,12,40,39,68,91}
- * Output: it returns either true or false
- * 1st approach Time Complexity : O(n)
- * Auxiliary Space Complexity : O(1)
- */
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java b/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
index 5d31d40dacdc..d15ea1f78a78 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
@@ -1,13 +1,10 @@
-/**
- * Author : Siddhant Swarup Mallick
- * Github : https://github.com/siddhant2002
- */
-
-/** Program description - To find the New Man Shanks Prime. */
-/** Wikipedia Link - https://en.wikipedia.org/wiki/Newman%E2%80%93Shanks%E2%80%93Williams_prime */
-
package com.thealgorithms.dynamicprogramming;
+/**
+ * @author Siddhant Swarup Mallick
+ * Program description - To find the New Man Shanks Prime.
+ * Wikipedia
+ */
public final class NewManShanksPrime {
private NewManShanksPrime() {
}
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java b/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java
index 43427457e307..c07563ad0020 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/RegexMatching.java
@@ -6,8 +6,6 @@
* cover the entire text ?-> matches single characters *-> match the sequence of
* characters
*
- */
-/**
* For calculation of Time and Space Complexity. Let N be length of src and M be
* length of pat
*
diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount.java b/src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount.java
index cbe3ccae4ac7..0c5bc2c5884d 100644
--- a/src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount.java
+++ b/src/main/java/com/thealgorithms/dynamicprogramming/SubsetCount.java
@@ -3,8 +3,8 @@
/**
* Find the number of subsets present in the given array with a sum equal to target.
* Based on Solution discussed on
- * StackOverflow(https://stackoverflow.com/questions/22891076/count-number-of-subsets-with-sum-equal-to-k)
- * @author Samrat Podder(https://github.com/samratpodder)
+ * StackOverflow
+ * @author Samrat Podder
*/
public final class SubsetCount {
private SubsetCount() {
@@ -19,7 +19,7 @@ private SubsetCount() {
*
*/
public static int getCount(int[] arr, int target) {
- /**
+ /*
* Base Cases - If target becomes zero, we have reached the required sum for the subset
* If we reach the end of the array arr then, either if target==arr[end], then we add one to
* the final count Otherwise we add 0 to the final count
diff --git a/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java b/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java
index 03c8a8989bb2..31f81da63f03 100644
--- a/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java
+++ b/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java
@@ -1,15 +1,13 @@
package com.thealgorithms.maths;
+import java.math.BigInteger;
/**
- * Wikipedia link for Automorphic Number : https://en.wikipedia.org/wiki/Automorphic_number
+ * Automorphic Number
* A number is said to be an Automorphic, if it is present in the last digit(s)
* of its square. Example- Let the number be 25, its square is 625. Since,
* 25(The input number) is present in the last two digits of its square(625), it
* is an Automorphic Number.
*/
-
-import java.math.BigInteger;
-
public final class AutomorphicNumber {
private AutomorphicNumber() {
}
diff --git a/src/main/java/com/thealgorithms/maths/DigitalRoot.java b/src/main/java/com/thealgorithms/maths/DigitalRoot.java
index 84b33f34c393..e8f5305c7569 100644
--- a/src/main/java/com/thealgorithms/maths/DigitalRoot.java
+++ b/src/main/java/com/thealgorithms/maths/DigitalRoot.java
@@ -1,8 +1,7 @@
+package com.thealgorithms.maths;
+
/**
- * Author : Suraj Kumar Modi
- * https://github.com/skmodi649
- */
-/**
+ * @author Suraj Kumar Modi
* You are given a number n. You need to find the digital root of n.
* DigitalRoot of a number is the recursive sum of its digits until we get a single digit number.
*
@@ -20,8 +19,6 @@
* which is not a single digit number, hence
* sum of digit of 45 is 9 which is a single
* digit number.
- */
-/**
* Algorithm :
* Step 1 : Define a method digitalRoot(int n)
* Step 2 : Define another method single(int n)
@@ -38,8 +35,6 @@
* Step 5 : In main method simply take n as input and then call digitalRoot(int n) function and
* print the result
*/
-package com.thealgorithms.maths;
-
final class DigitalRoot {
private DigitalRoot() {
}
@@ -53,6 +48,11 @@ public static int digitalRoot(int n) {
}
}
+ /**
+ * Time Complexity: O((Number of Digits)^2) Auxiliary Space Complexity:
+ * O(Number of Digits) Constraints: 1 <= n <= 10^7
+ */
+
// This function is used for finding the sum of the digits of number
public static int single(int n) {
if (n <= 9) { // if n becomes less than 10 than return n
@@ -63,7 +63,3 @@ public static int single(int n) {
} // n / 10 is the number obtained after removing the digit one by one
// The Sum of digits is stored in the Stack memory and then finally returned
}
-/**
- * Time Complexity: O((Number of Digits)^2) Auxiliary Space Complexity:
- * O(Number of Digits) Constraints: 1 <= n <= 10^7
- */
diff --git a/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java b/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java
index a0dbfb1f70a4..01a52b913d30 100644
--- a/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java
+++ b/src/main/java/com/thealgorithms/maths/FastInverseSqrt.java
@@ -1,18 +1,26 @@
-/**
- * Author : Siddhant Swarup Mallick
- * Github : https://github.com/siddhant2002
- */
-
-/** Program description - To find out the inverse square root of the given number*/
-
-/** Wikipedia Link - https://en.wikipedia.org/wiki/Fast_inverse_square_root */
-
package com.thealgorithms.maths;
+/**
+ * @author Siddhant Swarup Mallick
+ * Program description - To find out the inverse square root of the given number
+ * Wikipedia
+ */
public final class FastInverseSqrt {
private FastInverseSqrt() {
}
-
+ /**
+ * Returns the inverse square root of the given number upto 6 - 8 decimal places.
+ * calculates the inverse square root of the given number and returns true if calculated answer
+ * matches with given answer else returns false
+ *
+ * OUTPUT :
+ * Input - number = 4522
+ * Output: it calculates the inverse squareroot of a number and returns true with it matches the
+ * given answer else returns false. 1st approach Time Complexity : O(1) Auxiliary Space Complexity :
+ * O(1) Input - number = 4522 Output: it calculates the inverse squareroot of a number and returns
+ * true with it matches the given answer else returns false. 2nd approach Time Complexity : O(1)
+ * Auxiliary Space Complexity : O(1)
+ */
public static boolean inverseSqrt(float number) {
float x = number;
float xhalf = 0.5f * x;
@@ -24,11 +32,10 @@ public static boolean inverseSqrt(float number) {
}
/**
- * Returns the inverse square root of the given number upto 6 - 8 decimal places.
+ * Returns the inverse square root of the given number upto 14 - 16 decimal places.
* calculates the inverse square root of the given number and returns true if calculated answer
* matches with given answer else returns false
*/
-
public static boolean inverseSqrt(double number) {
double x = number;
double xhalf = 0.5d * x;
@@ -41,18 +48,4 @@ public static boolean inverseSqrt(double number) {
x *= number;
return x == 1 / Math.sqrt(number);
}
- /**
- * Returns the inverse square root of the given number upto 14 - 16 decimal places.
- * calculates the inverse square root of the given number and returns true if calculated answer
- * matches with given answer else returns false
- */
}
-/**
- * OUTPUT :
- * Input - number = 4522
- * Output: it calculates the inverse squareroot of a number and returns true with it matches the
- * given answer else returns false. 1st approach Time Complexity : O(1) Auxiliary Space Complexity :
- * O(1) Input - number = 4522 Output: it calculates the inverse squareroot of a number and returns
- * true with it matches the given answer else returns false. 2nd approach Time Complexity : O(1)
- * Auxiliary Space Complexity : O(1)
- */
diff --git a/src/main/java/com/thealgorithms/maths/FrizzyNumber.java b/src/main/java/com/thealgorithms/maths/FrizzyNumber.java
index 3ae5e021df1b..ff2b00c26ce2 100644
--- a/src/main/java/com/thealgorithms/maths/FrizzyNumber.java
+++ b/src/main/java/com/thealgorithms/maths/FrizzyNumber.java
@@ -1,12 +1,9 @@
-/**
- * Author : Siddhant Swarup Mallick
- * Github : https://github.com/siddhant2002
- */
-
-/** Program description - To find the FrizzyNumber*/
-
package com.thealgorithms.maths;
+/**
+ * @author Siddhant Swarup Mallick
+ * Program description - To find the FrizzyNumber
+ */
public final class FrizzyNumber {
private FrizzyNumber() {
}
diff --git a/src/main/java/com/thealgorithms/maths/JosephusProblem.java b/src/main/java/com/thealgorithms/maths/JosephusProblem.java
index 7d19623b3ed0..98d839011a7f 100644
--- a/src/main/java/com/thealgorithms/maths/JosephusProblem.java
+++ b/src/main/java/com/thealgorithms/maths/JosephusProblem.java
@@ -5,9 +5,7 @@
* numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend
* brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings
* you to the 1st friend.
- */
-/**
The rules of the game are as follows:
1.Start at the 1st friend.
@@ -19,7 +17,6 @@
@author Kunal
*/
-
public final class JosephusProblem {
private JosephusProblem() {
}
diff --git a/src/main/java/com/thealgorithms/maths/PascalTriangle.java b/src/main/java/com/thealgorithms/maths/PascalTriangle.java
index 95f92fbe1b49..9a9d4450cb98 100644
--- a/src/main/java/com/thealgorithms/maths/PascalTriangle.java
+++ b/src/main/java/com/thealgorithms/maths/PascalTriangle.java
@@ -37,17 +37,17 @@ private PascalTriangle() {
*/
public static int[][] pascal(int n) {
- /**
+ /*
* @param arr An auxiliary array to store generated pascal triangle values
* @return
*/
int[][] arr = new int[n][n];
- /**
+ /*
* @param line Iterate through every line and print integer(s) in it
* @param i Represents the column number of the element we are currently on
*/
for (int line = 0; line < n; line++) {
- /**
+ /*
* @Every line has number of integers equal to line number
*/
for (int i = 0; i <= line; i++) {
diff --git a/src/main/java/com/thealgorithms/others/BankersAlgorithm.java b/src/main/java/com/thealgorithms/others/BankersAlgorithm.java
index a22d7c737415..836526529374 100644
--- a/src/main/java/com/thealgorithms/others/BankersAlgorithm.java
+++ b/src/main/java/com/thealgorithms/others/BankersAlgorithm.java
@@ -1,5 +1,7 @@
package com.thealgorithms.others;
+import java.util.Scanner;
+
/**
* This file contains an implementation of BANKER'S ALGORITM Wikipedia:
* https://en.wikipedia.org/wiki/Banker%27s_algorithm
@@ -18,8 +20,6 @@
*
* @author AMRITESH ANAND (https://github.com/amritesh19)
*/
-import java.util.Scanner;
-
public final class BankersAlgorithm {
private BankersAlgorithm() {
}
diff --git a/src/main/java/com/thealgorithms/others/Dijkstra.java b/src/main/java/com/thealgorithms/others/Dijkstra.java
index e2a778f8d6c3..a379100a2f3b 100644
--- a/src/main/java/com/thealgorithms/others/Dijkstra.java
+++ b/src/main/java/com/thealgorithms/others/Dijkstra.java
@@ -1,5 +1,9 @@
package com.thealgorithms.others;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.NavigableSet;
+import java.util.TreeSet;
/**
* Dijkstra's algorithm,is a graph search algorithm that solves the
* single-source shortest path problem for a graph with nonnegative edge path
@@ -15,11 +19,6 @@
* https://rosettacode.org/wiki/Dijkstra%27s_algorithm#Java Also most of the
* comments are from RosettaCode.
*/
-import java.util.HashMap;
-import java.util.Map;
-import java.util.NavigableSet;
-import java.util.TreeSet;
-
public final class Dijkstra {
private Dijkstra() {
}
diff --git a/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java b/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java
index 1f5f455f24e3..0924b8569942 100644
--- a/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java
+++ b/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java
@@ -1,11 +1,9 @@
package com.thealgorithms.others;
+import java.util.ArrayList;
/**
* @author Alexandros Lemonaris
*/
-
-import java.util.ArrayList;
-
public abstract class MemoryManagementAlgorithms {
/**
diff --git a/src/main/java/com/thealgorithms/others/RabinKarp.java b/src/main/java/com/thealgorithms/others/RabinKarp.java
index f8ca33becad3..cecf24e09b4a 100644
--- a/src/main/java/com/thealgorithms/others/RabinKarp.java
+++ b/src/main/java/com/thealgorithms/others/RabinKarp.java
@@ -1,12 +1,13 @@
package com.thealgorithms.others;
+import java.util.Scanner;
+
/**
* @author Prateek Kumar Oraon (https://github.com/prateekKrOraon)
+ *
+ An implementation of Rabin-Karp string matching algorithm
+ Program will simply end if there is no match
*/
-import java.util.Scanner;
-
-// An implementation of Rabin-Karp string matching algorithm
-// Program will simply end if there is no match
public final class RabinKarp {
private RabinKarp() {
}
diff --git a/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java b/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java
index 3930ca3e95ff..6ad0ef024342 100644
--- a/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java
+++ b/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java
@@ -1,11 +1,10 @@
package com.thealgorithms.others;
+import java.util.Scanner;
/**
* Given a matrix of size n x n We have to rotate this matrix by 90 Degree Here
* is the algorithm for this problem .
*/
-import java.util.Scanner;
-
final class RotateMatrixBy90Degrees {
private RotateMatrixBy90Degrees() {
}
diff --git a/src/main/java/com/thealgorithms/sorts/LinkListSort.java b/src/main/java/com/thealgorithms/sorts/LinkListSort.java
index c9000f7e3778..bf8910d94eae 100644
--- a/src/main/java/com/thealgorithms/sorts/LinkListSort.java
+++ b/src/main/java/com/thealgorithms/sorts/LinkListSort.java
@@ -1,14 +1,10 @@
-/**
- * Author : Siddhant Swarup Mallick
- * Github : https://github.com/siddhant2002
- */
-
-/** Program description - To sort the LinkList as per sorting technique */
-
package com.thealgorithms.sorts;
import java.util.Arrays;
-
+/**
+ * @author Siddhant Swarup Mallick
+ * Program description - To sort the LinkList as per sorting technique
+ */
public class LinkListSort {
public static boolean isSorted(int[] p, int option) {
@@ -116,17 +112,6 @@ public static boolean isSorted(int[] p, int option) {
// Switch case is used to call the classes as per the user requirement
return false;
}
-
- boolean compare(int[] a, int[] b) {
- for (int i = 0; i < a.length; i++) {
- if (a[i] != b[i]) {
- return false;
- }
- }
- return true;
- // Both the arrays are checked for equalness. If both are equal then true is
- // returned else false is returned
- }
/**
* OUTPUT :
* Input - {89,56,98,123,26,75,12,40,39,68,91} is same for all the 3 classes
@@ -138,6 +123,16 @@ boolean compare(int[] a, int[] b) {
* 3rd approach Time Complexity : O(n logn)
* Auxiliary Space Complexity : O(n)
*/
+ boolean compare(int[] a, int[] b) {
+ for (int i = 0; i < a.length; i++) {
+ if (a[i] != b[i]) {
+ return false;
+ }
+ }
+ return true;
+ // Both the arrays are checked for equalness. If both are equal then true is
+ // returned else false is returned
+ }
}
class Node {
diff --git a/src/main/java/com/thealgorithms/strings/Anagrams.java b/src/main/java/com/thealgorithms/strings/Anagrams.java
index 106be5e1a596..f5e8fa84cd41 100644
--- a/src/main/java/com/thealgorithms/strings/Anagrams.java
+++ b/src/main/java/com/thealgorithms/strings/Anagrams.java
@@ -12,8 +12,24 @@
*/
public class Anagrams {
- // 4 approaches are provided for anagram checking. approach 2 and approach 3 are similar but
- // differ in running time.
+ /**
+ * 4 approaches are provided for anagram checking. approach 2 and approach 3 are similar but
+ * differ in running time.
+ * OUTPUT :
+ * first string ="deal" second string ="lead"
+ * Output: Anagram
+ * Input and output is constant for all four approaches
+ * 1st approach Time Complexity : O(n logn)
+ * Auxiliary Space Complexity : O(1)
+ * 2nd approach Time Complexity : O(n)
+ * Auxiliary Space Complexity : O(1)
+ * 3rd approach Time Complexity : O(n)
+ * Auxiliary Space Complexity : O(1)
+ * 4th approach Time Complexity : O(n)
+ * Auxiliary Space Complexity : O(n)
+ * 5th approach Time Complexity: O(n)
+ * Auxiliary Space Complexity: O(1)
+ */
public static void main(String[] args) {
String first = "deal";
String second = "lead";
@@ -23,22 +39,6 @@ public static void main(String[] args) {
System.out.println(nm.approach1(first, second)); /* To activate methods for different approaches*/
System.out.println(nm.approach3(first, second)); /* To activate methods for different approaches*/
System.out.println(nm.approach4(first, second)); /* To activate methods for different approaches*/
- /**
- * OUTPUT :
- * first string ="deal" second string ="lead"
- * Output: Anagram
- * Input and output is constant for all four approaches
- * 1st approach Time Complexity : O(n logn)
- * Auxiliary Space Complexity : O(1)
- * 2nd approach Time Complexity : O(n)
- * Auxiliary Space Complexity : O(1)
- * 3rd approach Time Complexity : O(n)
- * Auxiliary Space Complexity : O(1)
- * 4th approach Time Complexity : O(n)
- * Auxiliary Space Complexity : O(n)
- * 5th approach Time Complexity: O(n)
- * Auxiliary Space Complexity: O(1)
- */
}
boolean approach1(String s, String t) {
diff --git a/src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java b/src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java
index 13761ac23e44..f54070d39cdd 100644
--- a/src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java
+++ b/src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java
@@ -1,15 +1,13 @@
package com.thealgorithms.bitmanipulation;
-/**
- * test Cases of Numbers Different Signs
- * @author Bama Charan Chhandogi
- */
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
-
+/**
+ * test Cases of Numbers Different Signs
+ * @author Bama Charan Chhandogi
+ */
class NumbersDifferentSignsTest {
@Test
diff --git a/src/test/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithmTest.java b/src/test/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithmTest.java
index 579e236699b3..8cd0b0a6838f 100644
--- a/src/test/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithmTest.java
+++ b/src/test/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithmTest.java
@@ -30,7 +30,7 @@ public void testBoruvkaMSTV9E14() {
edges.add(new BoruvkaAlgorithm.Edge(7, 8, 11));
final var graph = new Graph(9, edges);
- /**
+ /*
* Adjacency matrix
* 0 1 2 3 4 5 6 7 8
* 0 0 10 12 0 0 0 0 0 0
@@ -56,7 +56,7 @@ void testBoruvkaMSTV2E1() {
final var graph = new Graph(2, edges);
- /**
+ /*
* Adjacency matrix
* 0 1
* 0 0 10
@@ -79,7 +79,7 @@ void testCompleteGraphK4() {
final var graph = new Graph(4, edges);
- /**
+ /*
* Adjacency matrix
* 0 1 2 3
* 0 0 7 2 5
diff --git a/src/test/java/com/thealgorithms/datastructures/lists/QuickSortLinkedListTest.java b/src/test/java/com/thealgorithms/datastructures/lists/QuickSortLinkedListTest.java
index c4113b787de9..91e2ba5d43ce 100644
--- a/src/test/java/com/thealgorithms/datastructures/lists/QuickSortLinkedListTest.java
+++ b/src/test/java/com/thealgorithms/datastructures/lists/QuickSortLinkedListTest.java
@@ -1,16 +1,14 @@
package com.thealgorithms.datastructures.lists;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
/**
* Test cases for QuickSortLinkedList
* Author: Prabhat-Kumar-42
* GitHub: https://github.com/Prabhat-Kumar-42
*/
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-import org.junit.jupiter.api.Test;
-
public class QuickSortLinkedListTest {
@Test
diff --git a/src/test/java/com/thealgorithms/datastructures/lists/ReverseKGroupTest.java b/src/test/java/com/thealgorithms/datastructures/lists/ReverseKGroupTest.java
index c03f5b14c641..e7e3cca4083f 100644
--- a/src/test/java/com/thealgorithms/datastructures/lists/ReverseKGroupTest.java
+++ b/src/test/java/com/thealgorithms/datastructures/lists/ReverseKGroupTest.java
@@ -1,15 +1,13 @@
package com.thealgorithms.datastructures.lists;
-/**
- * Test cases for Reverse K Group LinkedList
- * Author: Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
- */
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
-
+/**
+ * Test cases for Reverse K Group LinkedList
+ * Author: Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
+ */
public class ReverseKGroupTest {
@Test
diff --git a/src/test/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedListsTest.java b/src/test/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedListsTest.java
index d3c020f8881b..8b2ae424364e 100644
--- a/src/test/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedListsTest.java
+++ b/src/test/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedListsTest.java
@@ -1,15 +1,14 @@
package com.thealgorithms.datastructures.lists;
-/**
- * Test cases for RotateSinglyLinkedLists
- * Author: Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
- */
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
+/**
+ * Test cases for RotateSinglyLinkedLists
+ * Author: Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
+ */
public class RotateSinglyLinkedListsTest {
@Test
diff --git a/src/test/java/com/thealgorithms/scheduling/PreemptivePrioritySchedulingTest.java b/src/test/java/com/thealgorithms/scheduling/PreemptivePrioritySchedulingTest.java
index 61e2a2ac2690..1c8a25dfda49 100644
--- a/src/test/java/com/thealgorithms/scheduling/PreemptivePrioritySchedulingTest.java
+++ b/src/test/java/com/thealgorithms/scheduling/PreemptivePrioritySchedulingTest.java
@@ -1,10 +1,5 @@
package com.thealgorithms.scheduling;
-/**
- * Test Cases of Preemptive Priority Scheduling Algorithm
- * @author [Bama Charan Chhandogi](https://www.github.com/BamaCharanChhandogi)
- */
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
@@ -12,6 +7,10 @@
import java.util.List;
import org.junit.jupiter.api.Test;
+/**
+ * Test Cases of Preemptive Priority Scheduling Algorithm
+ * @author [Bama Charan Chhandogi](https://www.github.com/BamaCharanChhandogi)
+ */
class PreemptivePrioritySchedulingTest {
@Test
diff --git a/src/test/java/com/thealgorithms/strings/WordLadderTest.java b/src/test/java/com/thealgorithms/strings/WordLadderTest.java
index 4f1d07ebdc4a..c59f2d8b31be 100644
--- a/src/test/java/com/thealgorithms/strings/WordLadderTest.java
+++ b/src/test/java/com/thealgorithms/strings/WordLadderTest.java
@@ -8,30 +8,32 @@
public class WordLadderTest {
+ /**
+ * Test 1:
+ * Input: beginWord = "hit", endWord = "cog", wordList =
+ * ["hot","dot","dog","lot","log","cog"]
+ * Output: 5
+ * Explanation: One shortest transformation sequence is
+ * "hit" -> "hot" -> "dot" -> "dog" -> cog"
+ * which is 5 words long.
+ */
@Test
public void testWordLadder() {
- /**
- * Test 1:
- * Input: beginWord = "hit", endWord = "cog", wordList =
- * ["hot","dot","dog","lot","log","cog"]
- * Output: 5
- * Explanation: One shortest transformation sequence is
- * "hit" -> "hot" -> "dot" -> "dog" -> cog"
- * which is 5 words long.
- */
-
List wordList1 = Arrays.asList("hot", "dot", "dog", "lot", "log", "cog");
assertEquals(WordLadder.ladderLength("hit", "cog", wordList1), 5);
+ }
- /**
- * Test 2:
- * Input: beginWord = "hit", endWord = "cog", wordList =
- * ["hot","dot","dog","lot","log"]
- * Output: 0
- * Explanation: The endWord "cog" is not in wordList,
- * therefore there is no valid transformation sequence.
- */
+ /**
+ * Test 2:
+ * Input: beginWord = "hit", endWord = "cog", wordList =
+ * ["hot","dot","dog","lot","log"]
+ * Output: 0
+ * Explanation: The endWord "cog" is not in wordList,
+ * therefore there is no valid transformation sequence.
+ */
+ @Test
+ public void testWordLadder2() {
List wordList2 = Arrays.asList("hot", "dot", "dog", "lot", "log");
assertEquals(WordLadder.ladderLength("hit", "cog", wordList2), 0);