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

@ -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 {