style: enable InvalidJavadocPosition in checkstyle (#5237)

enable style InvalidJavadocPosition

Co-authored-by: Samuel Facchinello <samuel.facchinello@piksel.com>
This commit is contained in:
Samuel Facchinello
2024-06-18 19:34:22 +02:00
committed by GitHub
parent 39e065437c
commit 74e51990c1
37 changed files with 284 additions and 358 deletions

View File

@ -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
* <a href="https://en.wikipedia.org/wiki/Shortest_path_problem">Wikipedia</a>
*
* @author <a href="https://github.com/siddhant2002">Siddhant Swarup Mallick</a>
*/
public class AllPathsFromSourceToTarget {
// No. of vertices in graph

View File

@ -2,9 +2,9 @@ package com.thealgorithms.datastructures.graphs;
/**
* Java program for Hamiltonian Cycle
* (https://en.wikipedia.org/wiki/Hamiltonian_path)
* <a href="https://en.wikipedia.org/wiki/Hamiltonian_path">wikipedia</a>
*
* @author Akshay Dubey (https://github.com/itsAkshayDubey)
* @author <a href="https://github.com/itsAkshayDubey">Akshay Dubey</a>
*/
public class HamiltonianCycle {
@ -58,31 +58,31 @@ public class HamiltonianCycle {
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;
}
}

View File

@ -8,9 +8,6 @@ import java.util.Map;
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
*/

View File

@ -6,53 +6,50 @@ import java.util.Stack;
/**
* Java program that implements Kosaraju Algorithm.
* @author Shivanagouda S A (https://github.com/shivu2002a)
*
*/
/**
* @author <a href="https://github.com/shivu2002a">Shivanagouda S A</a>
* <p>
* 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.
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
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.
We can observe that this graph has the same SCC as that of original graph.
*/

View File

@ -6,51 +6,48 @@ import java.util.Stack;
/**
* Java program that implements Tarjan's Algorithm.
* @author Shivanagouda S A (https://github.com/shivu2002a)
*
*/
/**
* @author <a href="https://github.com/shivu2002a">Shivanagouda S A</a>
* <p>
* 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
0 --------> 1 -------> 3 --------> 4
^ /
| /
| /
| /
| /
| /
| /
| /
| /
| /
|V
2
For the above graph, the SCC list goes as follows:
1, 2, 0
3
4
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.
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).
{@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 Tarjans
algorithm does the same in a single DFS, which leads to much lower constant factors in the latter.
* Kosaraju Algorithm aims at doing the same but uses two DFS traversalse whereas Tarjans
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<List<Integer>> sccList = new ArrayList<List<Integer>>();
private final List<List<Integer>> sccList = new ArrayList<List<Integer>>();
public List<List<Integer>> stronglyConnectedComponents(int v, List<List<Integer>> graph) {

View File

@ -1,43 +1,37 @@
/**
* Author : Suraj Kumar
* Github : https://github.com/skmodi649
*/
/**
* 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;
/**
* @author <a href="https://github.com/skmodi649">Suraj Kumar</a>
* <p>
* PROBLEM DESCRIPTION :
* There is a single linked list and we are supposed to find a random node in the given linked list
* <p>
* 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
* <p>
* (a) RandomNode(head)
* (b) run a while loop till null;
* (c) add the value to arraylist;
* (d) increase the size;
* <p>
* 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
*/
public class RandomNode {
private List<Integer> list;
private final List<Integer> 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 class RandomNode {
}
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 class RandomNode {
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)
*/

View File

@ -5,7 +5,7 @@ import java.util.NoSuchElementException;
import java.util.StringJoiner;
/**
* https://en.wikipedia.org/wiki/Linked_list
* <a href="https://en.wikipedia.org/wiki/Linked_list">wikipedia</a>
*/
public class SinglyLinkedList implements Iterable<Integer> {
@ -95,7 +95,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
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 class SinglyLinkedList implements Iterable<Integer> {
size++;
}
/**
* Swaps nodes of two given values a and b.
*
*/
/**
* Deletes a node at the head
*/

View File

@ -18,8 +18,6 @@ import com.thealgorithms.datastructures.trees.BinaryTree.Node;
*
* 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

View File

@ -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 <a href="https://github.com/dheeraj92">Dheeraj Kumar Barnwal</a>
*/
import java.util.Scanner;
public class TrieImp {
public class TrieNode {

View File

@ -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 : <a href="https://en.wikipedia.org/wiki/Catalan_number">Wikipedia</a>
*
* Time Complexity: O(n^2) Space Complexity: O(n)
*
* @author AMRITESH ANAND (https://github.com/amritesh19)
* @author <a href="https://github.com/amritesh19">AMRITESH ANAND</a>
*/
import java.util.Scanner;
public final class CatalanNumber {
private CatalanNumber() {
}
@ -31,7 +30,7 @@ public final class CatalanNumber {
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
*/

View File

@ -1,20 +1,14 @@
/**
* Author : Siddhant Swarup Mallick
* Github : https://github.com/siddhant2002
*/
/**
* 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
*/
/** Program description - To find the Golomb sequence upto n */
package com.thealgorithms.dynamicprogramming;
/**
* @author <a href="https://github.com/siddhant2002">Siddhant Swarup Mallick</a>
* 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.
* <a href="https://en.wikipedia.org/wiki/Golomb_sequence">Wikipedia</a>
* Program description - To find the Golomb sequence upto n
*/
public final class CountFriendsPairing {
private CountFriendsPairing() {
}

View File

@ -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 @@ package com.thealgorithms.dynamicprogramming;
*
* @author SUBHAM SANGHAI
*/
import java.util.Scanner;
public final class EditDistance {
private EditDistance() {
}

View File

@ -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 <a href="https://github.com/siddhant2002">Siddhant Swarup Mallick</a>
* 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 final class KadaneAlgorithm {
// 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)
*/
}

View File

@ -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 <a href="https://github.com/siddhant2002">Siddhant Swarup Mallick</a>
* Program description - To find the New Man Shanks Prime.
* <a href="https://en.wikipedia.org/wiki/Newman%E2%80%93Shanks%E2%80%93Williams_prime">Wikipedia</a>
*/
public final class NewManShanksPrime {
private NewManShanksPrime() {
}

View File

@ -6,8 +6,6 @@ package com.thealgorithms.dynamicprogramming;
* 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
*

View File

@ -3,8 +3,8 @@ package com.thealgorithms.dynamicprogramming;
/**
* 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)
* <a href="https://stackoverflow.com/questions/22891076/count-number-of-subsets-with-sum-equal-to-k">StackOverflow</a>
* @author <a href="https://github.com/samratpodder">Samrat Podder</a>
*/
public final class SubsetCount {
private SubsetCount() {
@ -19,7 +19,7 @@ public final class 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

View File

@ -1,15 +1,13 @@
package com.thealgorithms.maths;
import java.math.BigInteger;
/**
* Wikipedia link for Automorphic Number : https://en.wikipedia.org/wiki/Automorphic_number
* <a href="https://en.wikipedia.org/wiki/Automorphic_number">Automorphic Number</a>
* 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() {
}

View File

@ -1,8 +1,7 @@
package com.thealgorithms.maths;
/**
* Author : Suraj Kumar Modi
* https://github.com/skmodi649
*/
/**
* @author <a href="https://github.com/skmodi649">Suraj Kumar Modi</a>
* 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 @@ final class DigitalRoot {
}
}
/**
* 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 @@ final class DigitalRoot {
} // 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
*/

View File

@ -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 <a href="https://github.com/siddhant2002">Siddhant Swarup Mallick</a>
* Program description - To find out the inverse square root of the given number
* <a href="https://en.wikipedia.org/wiki/Fast_inverse_square_root">Wikipedia</a>
*/
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 final class FastInverseSqrt {
}
/**
* 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 final class FastInverseSqrt {
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)
*/

View File

@ -1,12 +1,9 @@
/**
* Author : Siddhant Swarup Mallick
* Github : https://github.com/siddhant2002
*/
/** Program description - To find the FrizzyNumber*/
package com.thealgorithms.maths;
/**
* @author <a href="https://github.com/siddhant2002">Siddhant Swarup Mallick</a>
* Program description - To find the FrizzyNumber
*/
public final class FrizzyNumber {
private FrizzyNumber() {
}

View File

@ -5,9 +5,7 @@ package com.thealgorithms.maths;
* 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 @@ package com.thealgorithms.maths;
@author Kunal
*/
public final class JosephusProblem {
private JosephusProblem() {
}

View File

@ -37,17 +37,17 @@ public final class 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++) {

View File

@ -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 @@ package com.thealgorithms.others;
*
* @author AMRITESH ANAND (https://github.com/amritesh19)
*/
import java.util.Scanner;
public final class BankersAlgorithm {
private BankersAlgorithm() {
}

View File

@ -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 @@ package com.thealgorithms.others;
* 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() {
}

View File

@ -1,11 +1,9 @@
package com.thealgorithms.others;
import java.util.ArrayList;
/**
* @author Alexandros Lemonaris
*/
import java.util.ArrayList;
public abstract class MemoryManagementAlgorithms {
/**

View File

@ -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() {
}

View File

@ -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() {
}

View File

@ -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 <a href="https://github.com/siddhant2002">Siddhant Swarup Mallick</a>
* 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 class LinkListSort {
// 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 @@ public class LinkListSort {
* 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 {

View File

@ -12,8 +12,24 @@ import java.util.HashMap;
*/
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 class Anagrams {
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) {