mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 03:59:38 +08:00
style: enable InvalidJavadocPosition
in checkstyle (#5237)
enable style InvalidJavadocPosition Co-authored-by: Samuel Facchinello <samuel.facchinello@piksel.com>
This commit is contained in:

committed by
GitHub

parent
39e065437c
commit
74e51990c1
@ -99,7 +99,7 @@
|
|||||||
|
|
||||||
<!-- Checks for Javadoc comments. -->
|
<!-- Checks for Javadoc comments. -->
|
||||||
<!-- See https://checkstyle.org/checks/javadoc/index.html -->
|
<!-- See https://checkstyle.org/checks/javadoc/index.html -->
|
||||||
<!-- TODO <module name="InvalidJavadocPosition"/> -->
|
<module name="InvalidJavadocPosition"/>
|
||||||
<!-- TODO <module name="JavadocMethod"/> -->
|
<!-- TODO <module name="JavadocMethod"/> -->
|
||||||
<!-- TODO <module name="JavadocType"/> -->
|
<!-- TODO <module name="JavadocType"/> -->
|
||||||
<!-- TODO <module name="JavadocVariable"/> -->
|
<!-- TODO <module name="JavadocVariable"/> -->
|
||||||
|
@ -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;
|
package com.thealgorithms.backtracking;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 {
|
public class AllPathsFromSourceToTarget {
|
||||||
|
|
||||||
// No. of vertices in graph
|
// No. of vertices in graph
|
||||||
|
@ -2,9 +2,9 @@ package com.thealgorithms.datastructures.graphs;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Java program for Hamiltonian Cycle
|
* 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 {
|
public class HamiltonianCycle {
|
||||||
|
|
||||||
@ -58,31 +58,31 @@ public class HamiltonianCycle {
|
|||||||
return true;
|
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) {
|
if (this.pathCount == this.vertex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int v = 0; v < this.vertex; v++) {
|
for (int v = 0; v < this.vertex; v++) {
|
||||||
/** if connected **/
|
/* if connected **/
|
||||||
if (this.graph[vertex][v] == 1) {
|
if (this.graph[vertex][v] == 1) {
|
||||||
/** add to path **/
|
/* add to path **/
|
||||||
this.cycle[this.pathCount++] = v;
|
this.cycle[this.pathCount++] = v;
|
||||||
|
|
||||||
/** remove connection **/
|
/* remove connection **/
|
||||||
this.graph[vertex][v] = 0;
|
this.graph[vertex][v] = 0;
|
||||||
this.graph[v][vertex] = 0;
|
this.graph[v][vertex] = 0;
|
||||||
|
|
||||||
/** if vertex not already selected solve recursively **/
|
/* if vertex not already selected solve recursively **/
|
||||||
if (!isPresent(v)) {
|
if (!isPresent(v)) {
|
||||||
return isPathFound(v);
|
return isPathFound(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** restore connection **/
|
/* restore connection **/
|
||||||
this.graph[vertex][v] = 1;
|
this.graph[vertex][v] = 1;
|
||||||
this.graph[v][vertex] = 1;
|
this.graph[v][vertex] = 1;
|
||||||
|
|
||||||
/** remove path **/
|
/* remove path **/
|
||||||
this.cycle[--this.pathCount] = -1;
|
this.cycle[--this.pathCount] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,6 @@ import java.util.Map;
|
|||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
|
||||||
* An algorithm that sorts a graph in toplogical order.
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* A class that represents the adjaceny list of a graph
|
* A class that represents the adjaceny list of a graph
|
||||||
*/
|
*/
|
||||||
|
@ -6,11 +6,8 @@ import java.util.Stack;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Java program that implements Kosaraju Algorithm.
|
* 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
|
* 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
|
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
|
transpose graph (same graph with all the edges reversed) has exactly the same SCCs as the original
|
||||||
|
@ -6,11 +6,8 @@ import java.util.Stack;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Java program that implements Tarjan's Algorithm.
|
* 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
|
* 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.
|
||||||
|
|
||||||
@ -58,7 +55,7 @@ public class TarjansAlgorithm {
|
|||||||
// Timer for tracking lowtime and insertion time
|
// Timer for tracking lowtime and insertion time
|
||||||
private int 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) {
|
public List<List<Integer>> stronglyConnectedComponents(int v, List<List<Integer>> graph) {
|
||||||
|
|
||||||
|
@ -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;
|
package com.thealgorithms.datastructures.lists;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
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 {
|
public class RandomNode {
|
||||||
|
|
||||||
private List<Integer> list;
|
private final List<Integer> list;
|
||||||
private int size;
|
private int size;
|
||||||
private static Random rand = new Random();
|
private static final Random RAND = new Random();
|
||||||
|
|
||||||
static class ListNode {
|
static class ListNode {
|
||||||
|
|
||||||
@ -63,10 +57,23 @@ public class RandomNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getRandom() {
|
public int getRandom() {
|
||||||
int index = rand.nextInt(size);
|
int index = RAND.nextInt(size);
|
||||||
return list.get(index);
|
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
|
// Driver program to test above functions
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ListNode head = new ListNode(15);
|
ListNode head = new ListNode(15);
|
||||||
@ -80,18 +87,3 @@ public class RandomNode {
|
|||||||
System.out.println("Random Node : " + randomNum);
|
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)
|
|
||||||
*/
|
|
||||||
|
@ -5,7 +5,7 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.StringJoiner;
|
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> {
|
public class SinglyLinkedList implements Iterable<Integer> {
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
|
|||||||
previousB = currentB;
|
previousB = currentB;
|
||||||
currentB = currentB.next;
|
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) {
|
if (currentA == null || currentB == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -334,11 +334,6 @@ public class SinglyLinkedList implements Iterable<Integer> {
|
|||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Swaps nodes of two given values a and b.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a node at the head
|
* Deletes a node at the head
|
||||||
*/
|
*/
|
||||||
|
@ -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
|
* Ex.2. [30,20,40,10,25,35,50] represents level order traversal of a binary
|
||||||
* search tree. Find ceil for 52 Answer: -1
|
* search tree. Find ceil for 52 Answer: -1
|
||||||
*/
|
|
||||||
/**
|
|
||||||
*
|
*
|
||||||
* Solution 1: Brute Force Solution: Do an inorder traversal and save result
|
* 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
|
* into an array. Iterate over the array to get an element equal to or greater
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.thealgorithms.datastructures.trees;
|
package com.thealgorithms.datastructures.trees;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trie Data structure implementation without any libraries
|
* 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 TrieImp {
|
||||||
|
|
||||||
public class TrieNode {
|
public class TrieNode {
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package com.thealgorithms.dynamicprogramming;
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
/**
|
/**
|
||||||
* This file contains an implementation of finding the nth CATALAN NUMBER using
|
* 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)
|
* 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 {
|
public final class CatalanNumber {
|
||||||
private CatalanNumber() {
|
private CatalanNumber() {
|
||||||
}
|
}
|
||||||
@ -31,7 +30,7 @@ public final class CatalanNumber {
|
|||||||
catalanArray[0] = 1;
|
catalanArray[0] = 1;
|
||||||
catalanArray[1] = 1;
|
catalanArray[1] = 1;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* The Catalan numbers satisfy the recurrence relation C₀=1 and Cn = Σ
|
* The Catalan numbers satisfy the recurrence relation C₀=1 and Cn = Σ
|
||||||
* (Ci * Cn-1-i), i = 0 to n-1 , n > 0
|
* (Ci * Cn-1-i), i = 0 to n-1 , n > 0
|
||||||
*/
|
*/
|
||||||
|
@ -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;
|
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 {
|
public final class CountFriendsPairing {
|
||||||
private CountFriendsPairing() {
|
private CountFriendsPairing() {
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.thealgorithms.dynamicprogramming;
|
package com.thealgorithms.dynamicprogramming;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
/**
|
/**
|
||||||
* A DynamicProgramming based solution for Edit Distance problem In Java
|
* A DynamicProgramming based solution for Edit Distance problem In Java
|
||||||
* Description of Edit Distance with an Example:
|
* Description of Edit Distance with an Example:
|
||||||
@ -22,8 +23,6 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
*
|
*
|
||||||
* @author SUBHAM SANGHAI
|
* @author SUBHAM SANGHAI
|
||||||
*/
|
*/
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public final class EditDistance {
|
public final class EditDistance {
|
||||||
private EditDistance() {
|
private EditDistance() {
|
||||||
}
|
}
|
||||||
|
@ -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;
|
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 {
|
public final class KadaneAlgorithm {
|
||||||
private 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) {
|
public static boolean maxSum(int[] a, int predictedAnswer) {
|
||||||
int sum = a[0];
|
int sum = a[0];
|
||||||
int runningSum = 0;
|
int runningSum = 0;
|
||||||
@ -28,11 +33,4 @@ public final class KadaneAlgorithm {
|
|||||||
// It returns true if sum and predicted answer matches
|
// It returns true if sum and predicted answer matches
|
||||||
// The predicted answer is the answer itself. So it always return true
|
// 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)
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
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 {
|
public final class NewManShanksPrime {
|
||||||
private NewManShanksPrime() {
|
private NewManShanksPrime() {
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
* cover the entire text ?-> matches single characters *-> match the sequence of
|
* cover the entire text ?-> matches single characters *-> match the sequence of
|
||||||
* characters
|
* characters
|
||||||
*
|
*
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* For calculation of Time and Space Complexity. Let N be length of src and M be
|
* For calculation of Time and Space Complexity. Let N be length of src and M be
|
||||||
* length of pat
|
* length of pat
|
||||||
*
|
*
|
||||||
|
@ -3,8 +3,8 @@ package com.thealgorithms.dynamicprogramming;
|
|||||||
/**
|
/**
|
||||||
* Find the number of subsets present in the given array with a sum equal to target.
|
* Find the number of subsets present in the given array with a sum equal to target.
|
||||||
* Based on Solution discussed on
|
* Based on Solution discussed on
|
||||||
* StackOverflow(https://stackoverflow.com/questions/22891076/count-number-of-subsets-with-sum-equal-to-k)
|
* <a href="https://stackoverflow.com/questions/22891076/count-number-of-subsets-with-sum-equal-to-k">StackOverflow</a>
|
||||||
* @author Samrat Podder(https://github.com/samratpodder)
|
* @author <a href="https://github.com/samratpodder">Samrat Podder</a>
|
||||||
*/
|
*/
|
||||||
public final class SubsetCount {
|
public final class SubsetCount {
|
||||||
private SubsetCount() {
|
private SubsetCount() {
|
||||||
@ -19,7 +19,7 @@ public final class SubsetCount {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static int getCount(int[] arr, int target) {
|
public static int getCount(int[] arr, int target) {
|
||||||
/**
|
/*
|
||||||
* Base Cases - If target becomes zero, we have reached the required sum for the subset
|
* 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
|
* 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
|
* the final count Otherwise we add 0 to the final count
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package com.thealgorithms.maths;
|
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)
|
* 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,
|
* 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
|
* 25(The input number) is present in the last two digits of its square(625), it
|
||||||
* is an Automorphic Number.
|
* is an Automorphic Number.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
public final class AutomorphicNumber {
|
public final class AutomorphicNumber {
|
||||||
private AutomorphicNumber() {
|
private AutomorphicNumber() {
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author : Suraj Kumar Modi
|
* @author <a href="https://github.com/skmodi649">Suraj Kumar Modi</a>
|
||||||
* https://github.com/skmodi649
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* You are given a number n. You need to find the digital root of n.
|
* 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.
|
* 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
|
* which is not a single digit number, hence
|
||||||
* sum of digit of 45 is 9 which is a single
|
* sum of digit of 45 is 9 which is a single
|
||||||
* digit number.
|
* digit number.
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Algorithm :
|
* Algorithm :
|
||||||
* Step 1 : Define a method digitalRoot(int n)
|
* Step 1 : Define a method digitalRoot(int n)
|
||||||
* Step 2 : Define another method single(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
|
* Step 5 : In main method simply take n as input and then call digitalRoot(int n) function and
|
||||||
* print the result
|
* print the result
|
||||||
*/
|
*/
|
||||||
package com.thealgorithms.maths;
|
|
||||||
|
|
||||||
final class DigitalRoot {
|
final class DigitalRoot {
|
||||||
private 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
|
// This function is used for finding the sum of the digits of number
|
||||||
public static int single(int n) {
|
public static int single(int n) {
|
||||||
if (n <= 9) { // if n becomes less than 10 than return 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
|
} // 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
|
// 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
|
|
||||||
*/
|
|
||||||
|
@ -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;
|
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 {
|
public final class FastInverseSqrt {
|
||||||
private 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) {
|
public static boolean inverseSqrt(float number) {
|
||||||
float x = number;
|
float x = number;
|
||||||
float xhalf = 0.5f * x;
|
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
|
* calculates the inverse square root of the given number and returns true if calculated answer
|
||||||
* matches with given answer else returns false
|
* matches with given answer else returns false
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static boolean inverseSqrt(double number) {
|
public static boolean inverseSqrt(double number) {
|
||||||
double x = number;
|
double x = number;
|
||||||
double xhalf = 0.5d * x;
|
double xhalf = 0.5d * x;
|
||||||
@ -41,18 +48,4 @@ public final class FastInverseSqrt {
|
|||||||
x *= number;
|
x *= number;
|
||||||
return x == 1 / Math.sqrt(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)
|
|
||||||
*/
|
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
/**
|
|
||||||
* Author : Siddhant Swarup Mallick
|
|
||||||
* Github : https://github.com/siddhant2002
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** Program description - To find the FrizzyNumber*/
|
|
||||||
|
|
||||||
package com.thealgorithms.maths;
|
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 {
|
public final class FrizzyNumber {
|
||||||
private FrizzyNumber() {
|
private FrizzyNumber() {
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,7 @@ package com.thealgorithms.maths;
|
|||||||
* numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend
|
* 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
|
* 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.
|
* you to the 1st friend.
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
The rules of the game are as follows:
|
The rules of the game are as follows:
|
||||||
|
|
||||||
1.Start at the 1st friend.
|
1.Start at the 1st friend.
|
||||||
@ -19,7 +17,6 @@ package com.thealgorithms.maths;
|
|||||||
|
|
||||||
@author Kunal
|
@author Kunal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class JosephusProblem {
|
public final class JosephusProblem {
|
||||||
private JosephusProblem() {
|
private JosephusProblem() {
|
||||||
}
|
}
|
||||||
|
@ -37,17 +37,17 @@ public final class PascalTriangle {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public static int[][] pascal(int n) {
|
public static int[][] pascal(int n) {
|
||||||
/**
|
/*
|
||||||
* @param arr An auxiliary array to store generated pascal triangle values
|
* @param arr An auxiliary array to store generated pascal triangle values
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int[][] arr = new int[n][n];
|
int[][] arr = new int[n][n];
|
||||||
/**
|
/*
|
||||||
* @param line Iterate through every line and print integer(s) in it
|
* @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
|
* @param i Represents the column number of the element we are currently on
|
||||||
*/
|
*/
|
||||||
for (int line = 0; line < n; line++) {
|
for (int line = 0; line < n; line++) {
|
||||||
/**
|
/*
|
||||||
* @Every line has number of integers equal to line number
|
* @Every line has number of integers equal to line number
|
||||||
*/
|
*/
|
||||||
for (int i = 0; i <= line; i++) {
|
for (int i = 0; i <= line; i++) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.thealgorithms.others;
|
package com.thealgorithms.others;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file contains an implementation of BANKER'S ALGORITM Wikipedia:
|
* This file contains an implementation of BANKER'S ALGORITM Wikipedia:
|
||||||
* https://en.wikipedia.org/wiki/Banker%27s_algorithm
|
* https://en.wikipedia.org/wiki/Banker%27s_algorithm
|
||||||
@ -18,8 +20,6 @@ package com.thealgorithms.others;
|
|||||||
*
|
*
|
||||||
* @author AMRITESH ANAND (https://github.com/amritesh19)
|
* @author AMRITESH ANAND (https://github.com/amritesh19)
|
||||||
*/
|
*/
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public final class BankersAlgorithm {
|
public final class BankersAlgorithm {
|
||||||
private BankersAlgorithm() {
|
private BankersAlgorithm() {
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.thealgorithms.others;
|
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
|
* Dijkstra's algorithm,is a graph search algorithm that solves the
|
||||||
* single-source shortest path problem for a graph with nonnegative edge path
|
* 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
|
* https://rosettacode.org/wiki/Dijkstra%27s_algorithm#Java Also most of the
|
||||||
* comments are from RosettaCode.
|
* comments are from RosettaCode.
|
||||||
*/
|
*/
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.NavigableSet;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
public final class Dijkstra {
|
public final class Dijkstra {
|
||||||
private Dijkstra() {
|
private Dijkstra() {
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package com.thealgorithms.others;
|
package com.thealgorithms.others;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
/**
|
/**
|
||||||
* @author Alexandros Lemonaris
|
* @author Alexandros Lemonaris
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public abstract class MemoryManagementAlgorithms {
|
public abstract class MemoryManagementAlgorithms {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package com.thealgorithms.others;
|
package com.thealgorithms.others;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Prateek Kumar Oraon (https://github.com/prateekKrOraon)
|
* @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 {
|
public final class RabinKarp {
|
||||||
private RabinKarp() {
|
private RabinKarp() {
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package com.thealgorithms.others;
|
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
|
* Given a matrix of size n x n We have to rotate this matrix by 90 Degree Here
|
||||||
* is the algorithm for this problem .
|
* is the algorithm for this problem .
|
||||||
*/
|
*/
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
final class RotateMatrixBy90Degrees {
|
final class RotateMatrixBy90Degrees {
|
||||||
private RotateMatrixBy90Degrees() {
|
private RotateMatrixBy90Degrees() {
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package com.thealgorithms.sorts;
|
||||||
|
|
||||||
import java.util.Arrays;
|
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 class LinkListSort {
|
||||||
|
|
||||||
public static boolean isSorted(int[] p, int option) {
|
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
|
// Switch case is used to call the classes as per the user requirement
|
||||||
return false;
|
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 :
|
* OUTPUT :
|
||||||
* Input - {89,56,98,123,26,75,12,40,39,68,91} is same for all the 3 classes
|
* 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)
|
* 3rd approach Time Complexity : O(n logn)
|
||||||
* Auxiliary Space Complexity : O(n)
|
* 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 {
|
class Node {
|
||||||
|
@ -12,18 +12,9 @@ import java.util.HashMap;
|
|||||||
*/
|
*/
|
||||||
public class Anagrams {
|
public class Anagrams {
|
||||||
|
|
||||||
// 4 approaches are provided for anagram checking. approach 2 and approach 3 are similar but
|
|
||||||
// differ in running time.
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String first = "deal";
|
|
||||||
String second = "lead";
|
|
||||||
// All the below methods takes input but doesn't return any output to the main method.
|
|
||||||
Anagrams nm = new Anagrams();
|
|
||||||
System.out.println(nm.approach2(first, second)); /* To activate methods for different approaches*/
|
|
||||||
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*/
|
|
||||||
/**
|
/**
|
||||||
|
* 4 approaches are provided for anagram checking. approach 2 and approach 3 are similar but
|
||||||
|
* differ in running time.
|
||||||
* OUTPUT :
|
* OUTPUT :
|
||||||
* first string ="deal" second string ="lead"
|
* first string ="deal" second string ="lead"
|
||||||
* Output: Anagram
|
* Output: Anagram
|
||||||
@ -39,6 +30,15 @@ public class Anagrams {
|
|||||||
* 5th approach Time Complexity: O(n)
|
* 5th approach Time Complexity: O(n)
|
||||||
* Auxiliary Space Complexity: O(1)
|
* Auxiliary Space Complexity: O(1)
|
||||||
*/
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String first = "deal";
|
||||||
|
String second = "lead";
|
||||||
|
// All the below methods takes input but doesn't return any output to the main method.
|
||||||
|
Anagrams nm = new Anagrams();
|
||||||
|
System.out.println(nm.approach2(first, second)); /* To activate methods for different approaches*/
|
||||||
|
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*/
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean approach1(String s, String t) {
|
boolean approach1(String s, String t) {
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package com.thealgorithms.bitmanipulation;
|
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.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
/**
|
||||||
|
* test Cases of Numbers Different Signs
|
||||||
|
* @author Bama Charan Chhandogi
|
||||||
|
*/
|
||||||
class NumbersDifferentSignsTest {
|
class NumbersDifferentSignsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -30,7 +30,7 @@ public class BoruvkaAlgorithmTest {
|
|||||||
edges.add(new BoruvkaAlgorithm.Edge(7, 8, 11));
|
edges.add(new BoruvkaAlgorithm.Edge(7, 8, 11));
|
||||||
|
|
||||||
final var graph = new Graph(9, edges);
|
final var graph = new Graph(9, edges);
|
||||||
/**
|
/*
|
||||||
* Adjacency matrix
|
* Adjacency matrix
|
||||||
* 0 1 2 3 4 5 6 7 8
|
* 0 1 2 3 4 5 6 7 8
|
||||||
* 0 0 10 12 0 0 0 0 0 0
|
* 0 0 10 12 0 0 0 0 0 0
|
||||||
@ -56,7 +56,7 @@ public class BoruvkaAlgorithmTest {
|
|||||||
|
|
||||||
final var graph = new Graph(2, edges);
|
final var graph = new Graph(2, edges);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Adjacency matrix
|
* Adjacency matrix
|
||||||
* 0 1
|
* 0 1
|
||||||
* 0 0 10
|
* 0 0 10
|
||||||
@ -79,7 +79,7 @@ public class BoruvkaAlgorithmTest {
|
|||||||
|
|
||||||
final var graph = new Graph(4, edges);
|
final var graph = new Graph(4, edges);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Adjacency matrix
|
* Adjacency matrix
|
||||||
* 0 1 2 3
|
* 0 1 2 3
|
||||||
* 0 0 7 2 5
|
* 0 0 7 2 5
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
package com.thealgorithms.datastructures.lists;
|
package com.thealgorithms.datastructures.lists;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
/**
|
||||||
|
* Test cases for QuickSortLinkedList
|
||||||
|
* Author: Prabhat-Kumar-42
|
||||||
|
* GitHub: https://github.com/Prabhat-Kumar-42
|
||||||
|
*/
|
||||||
public class QuickSortLinkedListTest {
|
public class QuickSortLinkedListTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package com.thealgorithms.datastructures.lists;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
/**
|
||||||
|
* Test cases for Reverse K Group LinkedList
|
||||||
|
* Author: Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
||||||
|
*/
|
||||||
public class ReverseKGroupTest {
|
public class ReverseKGroupTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package com.thealgorithms.datastructures.lists;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test cases for RotateSinglyLinkedLists
|
||||||
|
* Author: Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi)
|
||||||
|
*/
|
||||||
public class RotateSinglyLinkedListsTest {
|
public class RotateSinglyLinkedListsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
package com.thealgorithms.scheduling;
|
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 static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -12,6 +7,10 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Cases of Preemptive Priority Scheduling Algorithm
|
||||||
|
* @author [Bama Charan Chhandogi](https://www.github.com/BamaCharanChhandogi)
|
||||||
|
*/
|
||||||
class PreemptivePrioritySchedulingTest {
|
class PreemptivePrioritySchedulingTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -8,9 +8,6 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
public class WordLadderTest {
|
public class WordLadderTest {
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWordLadder() {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test 1:
|
* Test 1:
|
||||||
* Input: beginWord = "hit", endWord = "cog", wordList =
|
* Input: beginWord = "hit", endWord = "cog", wordList =
|
||||||
@ -20,9 +17,12 @@ public class WordLadderTest {
|
|||||||
* "hit" -> "hot" -> "dot" -> "dog" -> cog"
|
* "hit" -> "hot" -> "dot" -> "dog" -> cog"
|
||||||
* which is 5 words long.
|
* which is 5 words long.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
|
public void testWordLadder() {
|
||||||
|
|
||||||
List<String> wordList1 = Arrays.asList("hot", "dot", "dog", "lot", "log", "cog");
|
List<String> wordList1 = Arrays.asList("hot", "dot", "dog", "lot", "log", "cog");
|
||||||
assertEquals(WordLadder.ladderLength("hit", "cog", wordList1), 5);
|
assertEquals(WordLadder.ladderLength("hit", "cog", wordList1), 5);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test 2:
|
* Test 2:
|
||||||
@ -32,6 +32,8 @@ public class WordLadderTest {
|
|||||||
* Explanation: The endWord "cog" is not in wordList,
|
* Explanation: The endWord "cog" is not in wordList,
|
||||||
* therefore there is no valid transformation sequence.
|
* therefore there is no valid transformation sequence.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
|
public void testWordLadder2() {
|
||||||
|
|
||||||
List<String> wordList2 = Arrays.asList("hot", "dot", "dog", "lot", "log");
|
List<String> wordList2 = Arrays.asList("hot", "dot", "dog", "lot", "log");
|
||||||
assertEquals(WordLadder.ladderLength("hit", "cog", wordList2), 0);
|
assertEquals(WordLadder.ladderLength("hit", "cog", wordList2), 0);
|
||||||
|
Reference in New Issue
Block a user