Skip to content

Commit 74e5199

Browse files
samuelfacSamuel Facchinello
and
Samuel Facchinello
authored
style: enable InvalidJavadocPosition in checkstyle (#5237)
enable style InvalidJavadocPosition Co-authored-by: Samuel Facchinello <[email protected]>
1 parent 39e0654 commit 74e5199

37 files changed

+273
-347
lines changed

checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
<!-- Checks for Javadoc comments. -->
101101
<!-- See https://checkstyle.org/checks/javadoc/index.html -->
102-
<!-- TODO <module name="InvalidJavadocPosition"/> -->
102+
<module name="InvalidJavadocPosition"/>
103103
<!-- TODO <module name="JavadocMethod"/> -->
104104
<!-- TODO <module name="JavadocType"/> -->
105105
<!-- TODO <module name="JavadocVariable"/> -->

src/main/java/com/thealgorithms/backtracking/AllPathsFromSourceToTarget.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
/**
2-
* Author : Siddhant Swarup Mallick
3-
* Github : https://github.com/siddhant2002
4-
*/
5-
6-
/** Program description - To find all possible paths from source to destination*/
7-
8-
/**Wikipedia link -> https://en.wikipedia.org/wiki/Shortest_path_problem */
91
package com.thealgorithms.backtracking;
102

113
import java.util.ArrayList;
124
import java.util.List;
135

6+
/**
7+
* Program description - To find all possible paths from source to destination
8+
* <a href="https://en.wikipedia.org/wiki/Shortest_path_problem">Wikipedia</a>
9+
*
10+
* @author <a href="https://github.com/siddhant2002">Siddhant Swarup Mallick</a>
11+
*/
1412
public class AllPathsFromSourceToTarget {
1513

1614
// No. of vertices in graph

src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
/**
44
* Java program for Hamiltonian Cycle
5-
* (https://en.wikipedia.org/wiki/Hamiltonian_path)
5+
* <a href="https://en.wikipedia.org/wiki/Hamiltonian_path">wikipedia</a>
66
*
7-
* @author Akshay Dubey (https://github.com/itsAkshayDubey)
7+
* @author <a href="https://github.com/itsAkshayDubey">Akshay Dubey</a>
88
*/
99
public class HamiltonianCycle {
1010

@@ -58,31 +58,31 @@ public boolean isPathFound(int vertex) {
5858
return true;
5959
}
6060

61-
/** all vertices selected but last vertex not linked to 0 **/
61+
/* all vertices selected but last vertex not linked to 0 **/
6262
if (this.pathCount == this.vertex) {
6363
return false;
6464
}
6565

6666
for (int v = 0; v < this.vertex; v++) {
67-
/** if connected **/
67+
/* if connected **/
6868
if (this.graph[vertex][v] == 1) {
69-
/** add to path **/
69+
/* add to path **/
7070
this.cycle[this.pathCount++] = v;
7171

72-
/** remove connection **/
72+
/* remove connection **/
7373
this.graph[vertex][v] = 0;
7474
this.graph[v][vertex] = 0;
7575

76-
/** if vertex not already selected solve recursively **/
76+
/* if vertex not already selected solve recursively **/
7777
if (!isPresent(v)) {
7878
return isPathFound(v);
7979
}
8080

81-
/** restore connection **/
81+
/* restore connection **/
8282
this.graph[vertex][v] = 1;
8383
this.graph[v][vertex] = 1;
8484

85-
/** remove path **/
85+
/* remove path **/
8686
this.cycle[--this.pathCount] = -1;
8787
}
8888
}

src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
import java.util.Queue;
99
import java.util.Set;
1010

11-
/**
12-
* An algorithm that sorts a graph in toplogical order.
13-
*/
1411
/**
1512
* A class that represents the adjaceny list of a graph
1613
*/

src/main/java/com/thealgorithms/datastructures/graphs/Kosaraju.java

+34-37
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,50 @@
66

77
/**
88
* Java program that implements Kosaraju Algorithm.
9-
* @author Shivanagouda S A (https://github.com/shivu2002a)
10-
*
11-
*/
12-
13-
/**
9+
* @author <a href="https://github.com/shivu2002a">Shivanagouda S A</a>
10+
* <p>
1411
* Kosaraju algorithm is a linear time algorithm to find the strongly connected components of a
15-
directed graph, which, from here onwards will be referred by SCC. It leverages the fact that the
16-
transpose graph (same graph with all the edges reversed) has exactly the same SCCs as the original
17-
graph.
12+
directed graph, which, from here onwards will be referred by SCC. It leverages the fact that the
13+
transpose graph (same graph with all the edges reversed) has exactly the same SCCs as the original
14+
graph.
1815
1916
* A graph is said to be strongly connected if every vertex is reachable from every other vertex.
20-
The SCCs of a directed graph form a partition into subgraphs that are themselves strongly
21-
connected. Single node is always a SCC.
17+
The SCCs of a directed graph form a partition into subgraphs that are themselves strongly
18+
connected. Single node is always a SCC.
2219
2320
* Example:
2421
25-
0 <--- 2 -------> 3 -------- > 4 ---- > 7
26-
| ^ | ^ ^
27-
| / | \ /
28-
| / | \ /
29-
v / v \ /
30-
1 5 --> 6
22+
0 <--- 2 -------> 3 -------- > 4 ---- > 7
23+
| ^ | ^ ^
24+
| / | \ /
25+
| / | \ /
26+
v / v \ /
27+
1 5 --> 6
3128
32-
For the above graph, the SCC list goes as follows:
33-
0, 1, 2
34-
3
35-
4, 5, 6
36-
7
29+
For the above graph, the SCC list goes as follows:
30+
0, 1, 2
31+
3
32+
4, 5, 6
33+
7
3734
38-
We can also see that order of the nodes in an SCC doesn't matter since they are in cycle.
35+
We can also see that order of the nodes in an SCC doesn't matter since they are in cycle.
3936
40-
{@summary}
37+
{@summary}
4138
* Kosaraju Algorithm:
42-
1. Perform DFS traversal of the graph. Push node to stack before returning. This gives edges
43-
sorted by lowest finish time.
44-
2. Find the transpose graph by reversing the edges.
45-
3. Pop nodes one by one from the stack and again to DFS on the modified graph.
46-
47-
The transpose graph of the above graph:
48-
0 ---> 2 <------- 3 <------- 4 <------ 7
49-
^ / ^ \ /
50-
| / | \ /
51-
| / | \ /
52-
| v | v v
53-
1 5 <--- 6
54-
55-
We can observe that this graph has the same SCC as that of original graph.
39+
1. Perform DFS traversal of the graph. Push node to stack before returning. This gives edges
40+
sorted by lowest finish time.
41+
2. Find the transpose graph by reversing the edges.
42+
3. Pop nodes one by one from the stack and again to DFS on the modified graph.
43+
44+
The transpose graph of the above graph:
45+
0 ---> 2 <------- 3 <------- 4 <------ 7
46+
^ / ^ \ /
47+
| / | \ /
48+
| / | \ /
49+
| v | v v
50+
1 5 <--- 6
51+
52+
We can observe that this graph has the same SCC as that of original graph.
5653
5754
*/
5855

src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java

+38-41
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,56 @@
66

77
/**
88
* Java program that implements Tarjan's Algorithm.
9-
* @author Shivanagouda S A (https://github.com/shivu2002a)
10-
*
11-
*/
12-
13-
/**
9+
* @author <a href="https://github.com/shivu2002a">Shivanagouda S A</a>
10+
* <p>
1411
* Tarjan's algorithm is a linear time algorithm to find the strongly connected components of a
15-
directed graph, which, from here onwards will be referred as SCC.
12+
directed graph, which, from here onwards will be referred as SCC.
1613
1714
* A graph is said to be strongly connected if every vertex is reachable from every other vertex.
18-
The SCCs of a directed graph form a partition into subgraphs that are themselves strongly
19-
connected. Single node is always a SCC.
15+
The SCCs of a directed graph form a partition into subgraphs that are themselves strongly
16+
connected. Single node is always a SCC.
2017
2118
* Example:
22-
0 --------> 1 -------> 3 --------> 4
23-
^ /
24-
| /
25-
| /
26-
| /
27-
| /
28-
| /
29-
| /
30-
| /
31-
| /
32-
| /
33-
|V
34-
2
35-
36-
For the above graph, the SCC list goes as follows:
37-
1, 2, 0
38-
3
39-
4
40-
41-
We can also see that order of the nodes in an SCC doesn't matter since they are in cycle.
42-
43-
{@summary}
44-
Tarjan's Algorithm:
45-
* DFS search produces a DFS tree
46-
* Strongly Connected Components form subtrees of the DFS tree.
47-
* If we can find the head of these subtrees, we can get all the nodes in that subtree (including
48-
the head) and that will be one SCC.
49-
* There is no back edge from one SCC to another (here can be cross edges, but they will not be
50-
used).
51-
52-
* Kosaraju Algorithm aims at doing the same but uses two DFS traversalse whereas Tarjan’s
53-
algorithm does the same in a single DFS, which leads to much lower constant factors in the latter.
19+
0 --------> 1 -------> 3 --------> 4
20+
^ /
21+
| /
22+
| /
23+
| /
24+
| /
25+
| /
26+
| /
27+
| /
28+
| /
29+
| /
30+
|V
31+
2
32+
33+
For the above graph, the SCC list goes as follows:
34+
1, 2, 0
35+
3
36+
4
37+
38+
We can also see that order of the nodes in an SCC doesn't matter since they are in cycle.
39+
40+
{@summary}
41+
Tarjan's Algorithm:
42+
* DFS search produces a DFS tree
43+
* Strongly Connected Components form subtrees of the DFS tree.
44+
* If we can find the head of these subtrees, we can get all the nodes in that subtree (including
45+
the head) and that will be one SCC.
46+
* There is no back edge from one SCC to another (here can be cross edges, but they will not be
47+
used).
48+
49+
* Kosaraju Algorithm aims at doing the same but uses two DFS traversalse whereas Tarjan’s
50+
algorithm does the same in a single DFS, which leads to much lower constant factors in the latter.
5451
5552
*/
5653
public class TarjansAlgorithm {
5754

5855
// Timer for tracking lowtime and insertion time
5956
private int time;
6057

61-
private List<List<Integer>> sccList = new ArrayList<List<Integer>>();
58+
private final List<List<Integer>> sccList = new ArrayList<List<Integer>>();
6259

6360
public List<List<Integer>> stronglyConnectedComponents(int v, List<List<Integer>> graph) {
6461

Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
1-
/**
2-
* Author : Suraj Kumar
3-
* Github : https://github.com/skmodi649
4-
*/
1+
package com.thealgorithms.datastructures.lists;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Random;
56

67
/**
8+
* @author <a href="https://github.com/skmodi649">Suraj Kumar</a>
9+
* <p>
710
* PROBLEM DESCRIPTION :
811
* There is a single linked list and we are supposed to find a random node in the given linked list
9-
*/
10-
11-
/**
12+
* <p>
1213
* ALGORITHM :
1314
* Step 1 : START
1415
* Step 2 : Create an arraylist of type integer
1516
* Step 3 : Declare an integer type variable for size and linked list type for head
1617
* Step 4 : We will use two methods, one for traversing through the linked list using while loop and
1718
* also increase the size by 1
18-
*
19+
* <p>
1920
* (a) RandomNode(head)
2021
* (b) run a while loop till null;
2122
* (c) add the value to arraylist;
2223
* (d) increase the size;
23-
*
24+
* <p>
2425
* Step 5 : Now use another method for getting random values using Math.random() and return the
2526
* value present in arraylist for the calculated index Step 6 : Now in main() method we will simply
2627
* insert nodes in the linked list and then call the appropriate method and then print the random
2728
* node generated Step 7 : STOP
2829
*/
29-
30-
package com.thealgorithms.datastructures.lists;
31-
32-
import java.util.ArrayList;
33-
import java.util.List;
34-
import java.util.Random;
35-
3630
public class RandomNode {
3731

38-
private List<Integer> list;
32+
private final List<Integer> list;
3933
private int size;
40-
private static Random rand = new Random();
34+
private static final Random RAND = new Random();
4135

4236
static class ListNode {
4337

@@ -63,10 +57,23 @@ public RandomNode(ListNode head) {
6357
}
6458

6559
public int getRandom() {
66-
int index = rand.nextInt(size);
60+
int index = RAND.nextInt(size);
6761
return list.get(index);
6862
}
6963

64+
/**
65+
* OUTPUT :
66+
* First output :
67+
* Random Node : 25
68+
* Second output :
69+
* Random Node : 78
70+
* Time Complexity : O(n)
71+
* Auxiliary Space Complexity : O(1)
72+
* Time Complexity : O(n)
73+
* Auxiliary Space Complexity : O(1)
74+
* Time Complexity : O(n)
75+
* Auxiliary Space Complexity : O(1)
76+
*/
7077
// Driver program to test above functions
7178
public static void main(String[] args) {
7279
ListNode head = new ListNode(15);
@@ -80,18 +87,3 @@ public static void main(String[] args) {
8087
System.out.println("Random Node : " + randomNum);
8188
}
8289
}
83-
/**
84-
* OUTPUT :
85-
* First output :
86-
* Random Node : 25
87-
* Second output :
88-
* Random Node : 78
89-
* Time Complexity : O(n)
90-
* Auxiliary Space Complexity : O(1)
91-
* Time Complexity : O(n)
92-
* Auxiliary Space Complexity : O(1)
93-
*/
94-
/**
95-
* Time Complexity : O(n)
96-
* Auxiliary Space Complexity : O(1)
97-
*/

0 commit comments

Comments
 (0)