mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-05 16:27:33 +08:00
style: enable ParameterName
in CheckStyle. (#5196)
* Enabled: ParameterName in CheckStyle. * Refactored to fix bug caused by selfAssignment of variables in VectorCrossproduct class
This commit is contained in:

committed by
GitHub

parent
2568b96784
commit
c42b1c940c
@ -114,7 +114,7 @@
|
||||
<module name="MemberName"/>
|
||||
<module name="MethodName"/>
|
||||
<module name="PackageName"/>
|
||||
<!-- TODO <module name="ParameterName"/> -->
|
||||
<module name="ParameterName"/>
|
||||
<module name="StaticVariableName"/>
|
||||
<!-- TODO <module name="TypeName"/> -->
|
||||
|
||||
|
@ -11,30 +11,30 @@ public class PowerSum {
|
||||
private int count = 0;
|
||||
private int sum = 0;
|
||||
|
||||
public int powSum(int N, int X) {
|
||||
sum(N, X, 1);
|
||||
public int powSum(int n, int x) {
|
||||
sum(n, x, 1);
|
||||
return count;
|
||||
}
|
||||
|
||||
// here i is the natural number which will be raised by X and added in sum.
|
||||
public void sum(int N, int X, int i) {
|
||||
public void sum(int n, int x, int i) {
|
||||
// if sum is equal to N that is one of our answer and count is increased.
|
||||
if (sum == N) {
|
||||
if (sum == n) {
|
||||
count++;
|
||||
return;
|
||||
} // we will be adding next natural number raised to X only if on adding it in sum the
|
||||
// result is less than N.
|
||||
else if (sum + power(i, X) <= N) {
|
||||
sum += power(i, X);
|
||||
sum(N, X, i + 1);
|
||||
else if (sum + power(i, x) <= n) {
|
||||
sum += power(i, x);
|
||||
sum(n, x, i + 1);
|
||||
// backtracking and removing the number added last since no possible combination is
|
||||
// there with it.
|
||||
sum -= power(i, X);
|
||||
sum -= power(i, x);
|
||||
}
|
||||
if (power(i, X) < N) {
|
||||
if (power(i, x) < n) {
|
||||
// calling the sum function with next natural number after backtracking if when it is
|
||||
// raised to X is still less than X.
|
||||
sum(N, X, i + 1);
|
||||
sum(n, x, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,31 +24,31 @@ public final class RomanToInteger {
|
||||
/**
|
||||
* This function convert Roman number into Integer
|
||||
*
|
||||
* @param A Roman number string
|
||||
* @param a Roman number string
|
||||
* @return integer
|
||||
*/
|
||||
public static int romanToInt(String A) {
|
||||
A = A.toUpperCase();
|
||||
public static int romanToInt(String a) {
|
||||
a = a.toUpperCase();
|
||||
char prev = ' ';
|
||||
|
||||
int sum = 0;
|
||||
|
||||
int newPrev = 0;
|
||||
for (int i = A.length() - 1; i >= 0; i--) {
|
||||
char c = A.charAt(i);
|
||||
for (int i = a.length() - 1; i >= 0; i--) {
|
||||
char c = a.charAt(i);
|
||||
|
||||
if (prev != ' ') {
|
||||
// checking current Number greater then previous or not
|
||||
// checking current Number greater than previous or not
|
||||
newPrev = ROMAN_TO_INT.get(prev) > newPrev ? ROMAN_TO_INT.get(prev) : newPrev;
|
||||
}
|
||||
|
||||
int currentNum = ROMAN_TO_INT.get(c);
|
||||
|
||||
// if current number greater then prev max previous then add
|
||||
// if current number greater than prev max previous then add
|
||||
if (currentNum >= newPrev) {
|
||||
sum += currentNum;
|
||||
} else {
|
||||
// subtract upcoming number until upcoming number not greater then prev max
|
||||
// subtract upcoming number until upcoming number not greater than prev max
|
||||
sum -= currentNum;
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,14 @@ public final class BipartiteGrapfDFS {
|
||||
private BipartiteGrapfDFS() {
|
||||
}
|
||||
|
||||
private static boolean bipartite(int V, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {
|
||||
private static boolean bipartite(int v, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {
|
||||
if (color[node] == -1) {
|
||||
color[node] = 1;
|
||||
}
|
||||
for (Integer it : adj.get(node)) {
|
||||
if (color[it] == -1) {
|
||||
color[it] = 1 - color[node];
|
||||
if (!bipartite(V, adj, color, it)) {
|
||||
if (!bipartite(v, adj, color, it)) {
|
||||
return false;
|
||||
}
|
||||
} else if (color[it] == color[node]) {
|
||||
@ -35,14 +35,14 @@ public final class BipartiteGrapfDFS {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isBipartite(int V, ArrayList<ArrayList<Integer>> adj) {
|
||||
public static boolean isBipartite(int v, ArrayList<ArrayList<Integer>> adj) {
|
||||
// Code here
|
||||
int[] color = new int[V + 1];
|
||||
int[] color = new int[v + 1];
|
||||
Arrays.fill(color, -1);
|
||||
|
||||
for (int i = 0; i < V; i++) {
|
||||
for (int i = 0; i < v; i++) {
|
||||
if (color[i] == -1) {
|
||||
if (!bipartite(V, adj, color, i)) {
|
||||
if (!bipartite(v, adj, color, i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,10 @@ public class FloydWarshall {
|
||||
this.numberofvertices = numberofvertices;
|
||||
}
|
||||
|
||||
public void floydwarshall(int[][] AdjacencyMatrix) { // calculates all the distances from source to destination vertex
|
||||
public void floydwarshall(int[][] adjacencyMatrix) { // calculates all the distances from source to destination vertex
|
||||
for (int source = 1; source <= numberofvertices; source++) {
|
||||
for (int destination = 1; destination <= numberofvertices; destination++) {
|
||||
distanceMatrix[source][destination] = AdjacencyMatrix[source][destination];
|
||||
distanceMatrix[source][destination] = adjacencyMatrix[source][destination];
|
||||
}
|
||||
}
|
||||
for (int intermediate = 1; intermediate <= numberofvertices; intermediate++) {
|
||||
|
@ -60,7 +60,7 @@ public class TarjansAlgorithm {
|
||||
|
||||
private 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) {
|
||||
|
||||
// Initially all vertices as unvisited, insertion and low time are undefined
|
||||
|
||||
@ -68,20 +68,20 @@ public class TarjansAlgorithm {
|
||||
|
||||
// lowTime: indicates the earliest visited vertex (the vertex with minimum insertion time)
|
||||
// that can be reached from a subtree rooted with a particular node.
|
||||
int[] lowTime = new int[V];
|
||||
int[] insertionTime = new int[V];
|
||||
for (int i = 0; i < V; i++) {
|
||||
int[] lowTime = new int[v];
|
||||
int[] insertionTime = new int[v];
|
||||
for (int i = 0; i < v; i++) {
|
||||
insertionTime[i] = -1;
|
||||
lowTime[i] = -1;
|
||||
}
|
||||
|
||||
// To check if element is present in stack
|
||||
boolean[] isInStack = new boolean[V];
|
||||
boolean[] isInStack = new boolean[v];
|
||||
|
||||
// Store nodes during DFS
|
||||
Stack<Integer> st = new Stack<Integer>();
|
||||
|
||||
for (int i = 0; i < V; i++) {
|
||||
for (int i = 0; i < v; i++) {
|
||||
if (insertionTime[i] == -1) stronglyConnCompsUtil(i, lowTime, insertionTime, isInStack, st, graph);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@ public class GenericHashMapUsingArray<K, V> {
|
||||
// 75, then adding 76th item it will double the size, copy all elements
|
||||
// & then add 76th item.
|
||||
|
||||
private void initBuckets(int N) {
|
||||
buckets = new LinkedList[N];
|
||||
private void initBuckets(int n) {
|
||||
buckets = new LinkedList[n];
|
||||
for (int i = 0; i < buckets.length; i++) {
|
||||
buckets[i] = new LinkedList<>();
|
||||
}
|
||||
|
@ -13,15 +13,15 @@ public class Merge_K_SortedLinkedlist {
|
||||
* This function merge K sorted LinkedList
|
||||
*
|
||||
* @param a array of LinkedList
|
||||
* @param N size of array
|
||||
* @param n size of array
|
||||
* @return node
|
||||
*/
|
||||
Node mergeKList(Node[] a, int N) {
|
||||
Node mergeKList(Node[] a, int n) {
|
||||
// Min Heap
|
||||
PriorityQueue<Node> min = new PriorityQueue<>(Comparator.comparingInt(x -> x.data));
|
||||
|
||||
// adding head of all linkedList in min heap
|
||||
min.addAll(Arrays.asList(a).subList(0, N));
|
||||
min.addAll(Arrays.asList(a).subList(0, n));
|
||||
|
||||
// Make new head among smallest heads in K linkedList
|
||||
Node head = min.poll();
|
||||
|
@ -32,16 +32,16 @@ public class SegmentTree {
|
||||
|
||||
/* A function which will update the value at a index i. This will be called by the
|
||||
update function internally*/
|
||||
private void updateTree(int start, int end, int index, int diff, int seg_index) {
|
||||
private void updateTree(int start, int end, int index, int diff, int segIndex) {
|
||||
if (index < start || index > end) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.segTree[seg_index] += diff;
|
||||
this.segTree[segIndex] += diff;
|
||||
if (start != end) {
|
||||
int mid = start + (end - start) / 2;
|
||||
updateTree(start, mid, index, diff, seg_index * 2 + 1);
|
||||
updateTree(mid + 1, end, index, diff, seg_index * 2 + 2);
|
||||
updateTree(start, mid, index, diff, segIndex * 2 + 1);
|
||||
updateTree(mid + 1, end, index, diff, segIndex * 2 + 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,17 +58,17 @@ public class SegmentTree {
|
||||
|
||||
/* A function to get the sum of the elements from index l to index r. This will be called
|
||||
* internally*/
|
||||
private int getSumTree(int start, int end, int q_start, int q_end, int seg_index) {
|
||||
if (q_start <= start && q_end >= end) {
|
||||
return this.segTree[seg_index];
|
||||
private int getSumTree(int start, int end, int qStart, int qEnd, int segIndex) {
|
||||
if (qStart <= start && qEnd >= end) {
|
||||
return this.segTree[segIndex];
|
||||
}
|
||||
|
||||
if (q_start > end || q_end < start) {
|
||||
if (qStart > end || qEnd < start) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mid = start + (end - start) / 2;
|
||||
return (getSumTree(start, mid, q_start, q_end, seg_index * 2 + 1) + getSumTree(mid + 1, end, q_start, q_end, seg_index * 2 + 2));
|
||||
return (getSumTree(start, mid, qStart, qEnd, segIndex * 2 + 1) + getSumTree(mid + 1, end, qStart, qEnd, segIndex * 2 + 2));
|
||||
}
|
||||
|
||||
/* A function to query the sum of the subarray [start...end]*/
|
||||
|
@ -27,15 +27,15 @@ public class BinaryExponentiation {
|
||||
}
|
||||
|
||||
// iterative function to calculate a to the power of b
|
||||
long power(long N, long M) {
|
||||
long power = N;
|
||||
long power(long n, long m) {
|
||||
long power = n;
|
||||
long sum = 1;
|
||||
while (M > 0) {
|
||||
if ((M & 1) == 1) {
|
||||
while (m > 0) {
|
||||
if ((m & 1) == 1) {
|
||||
sum *= power;
|
||||
}
|
||||
power = power * power;
|
||||
M = M >> 1;
|
||||
m = m >> 1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
@ -12,44 +12,44 @@ public final class BoundaryFill {
|
||||
* Get the color at the given co-odrinates of a 2D image
|
||||
*
|
||||
* @param image The image to be filled
|
||||
* @param x_co_ordinate The x co-ordinate of which color is to be obtained
|
||||
* @param y_co_ordinate The y co-ordinate of which color is to be obtained
|
||||
* @param xCoordinate The x co-ordinate of which color is to be obtained
|
||||
* @param yCoordinate The y co-ordinate of which color is to be obtained
|
||||
*/
|
||||
public static int getPixel(int[][] image, int x_co_ordinate, int y_co_ordinate) {
|
||||
return image[x_co_ordinate][y_co_ordinate];
|
||||
public static int getPixel(int[][] image, int xCoordinate, int yCoordinate) {
|
||||
return image[xCoordinate][yCoordinate];
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the color at the given co-odrinates of a 2D image
|
||||
*
|
||||
* @param image The image to be filed
|
||||
* @param x_co_ordinate The x co-ordinate at which color is to be filled
|
||||
* @param y_co_ordinate The y co-ordinate at which color is to be filled
|
||||
* @param xCoordinate The x co-ordinate at which color is to be filled
|
||||
* @param yCoordinate The y co-ordinate at which color is to be filled
|
||||
*/
|
||||
public static void putPixel(int[][] image, int x_co_ordinate, int y_co_ordinate, int new_color) {
|
||||
image[x_co_ordinate][y_co_ordinate] = new_color;
|
||||
public static void putPixel(int[][] image, int xCoordinate, int yCoordinate, int newColor) {
|
||||
image[xCoordinate][yCoordinate] = newColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the 2D image with new color
|
||||
*
|
||||
* @param image The image to be filed
|
||||
* @param x_co_ordinate The x co-ordinate at which color is to be filled
|
||||
* @param y_co_ordinate The y co-ordinate at which color is to be filled
|
||||
* @param new_color The new color which to be filled in the image
|
||||
* @param boundary_color The old color which is to be replaced in the image
|
||||
* @param xCoordinate The x co-ordinate at which color is to be filled
|
||||
* @param yCoordinate The y co-ordinate at which color is to be filled
|
||||
* @param newColor The new color which to be filled in the image
|
||||
* @param boundaryColor The old color which is to be replaced in the image
|
||||
*/
|
||||
public static void boundaryFill(int[][] image, int x_co_ordinate, int y_co_ordinate, int new_color, int boundary_color) {
|
||||
if (x_co_ordinate >= 0 && y_co_ordinate >= 0 && getPixel(image, x_co_ordinate, y_co_ordinate) != new_color && getPixel(image, x_co_ordinate, y_co_ordinate) != boundary_color) {
|
||||
putPixel(image, x_co_ordinate, y_co_ordinate, new_color);
|
||||
boundaryFill(image, x_co_ordinate + 1, y_co_ordinate, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate - 1, y_co_ordinate, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate, y_co_ordinate + 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate, y_co_ordinate - 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate + 1, y_co_ordinate - 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate - 1, y_co_ordinate + 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate + 1, y_co_ordinate + 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate - 1, y_co_ordinate - 1, new_color, boundary_color);
|
||||
public static void boundaryFill(int[][] image, int xCoordinate, int yCoordinate, int newColor, int boundaryColor) {
|
||||
if (xCoordinate >= 0 && yCoordinate >= 0 && getPixel(image, xCoordinate, yCoordinate) != newColor && getPixel(image, xCoordinate, yCoordinate) != boundaryColor) {
|
||||
putPixel(image, xCoordinate, yCoordinate, newColor);
|
||||
boundaryFill(image, xCoordinate + 1, yCoordinate, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate - 1, yCoordinate, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate, yCoordinate + 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate, yCoordinate - 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate + 1, yCoordinate - 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate - 1, yCoordinate + 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate + 1, yCoordinate + 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate - 1, yCoordinate - 1, newColor, boundaryColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,9 @@ public final class BruteForceKnapsack {
|
||||
// Returns the maximum value that
|
||||
// can be put in a knapsack of
|
||||
// capacity W
|
||||
static int knapSack(int W, int[] wt, int[] val, int n) {
|
||||
static int knapSack(int w, int[] wt, int[] val, int n) {
|
||||
// Base Case
|
||||
if (n == 0 || W == 0) {
|
||||
if (n == 0 || w == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -18,13 +18,13 @@ public final class BruteForceKnapsack {
|
||||
// more than Knapsack capacity W,
|
||||
// then this item cannot be included
|
||||
// in the optimal solution
|
||||
if (wt[n - 1] > W) {
|
||||
return knapSack(W, wt, val, n - 1);
|
||||
if (wt[n - 1] > w) {
|
||||
return knapSack(w, wt, val, n - 1);
|
||||
} // Return the maximum of two cases:
|
||||
// (1) nth item included
|
||||
// (2) not included
|
||||
else {
|
||||
return Math.max(val[n - 1] + knapSack(W - wt[n - 1], wt, val, n - 1), knapSack(W, wt, val, n - 1));
|
||||
return Math.max(val[n - 1] + knapSack(w - wt[n - 1], wt, val, n - 1), knapSack(w, wt, val, n - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ public final class KadaneAlgorithm {
|
||||
private KadaneAlgorithm() {
|
||||
}
|
||||
|
||||
public static boolean maxSum(int[] a, int predicted_answer) {
|
||||
public static boolean maxSum(int[] a, int predictedAnswer) {
|
||||
int sum = a[0];
|
||||
int runningSum = 0;
|
||||
for (int k : a) {
|
||||
@ -22,7 +22,7 @@ public final class KadaneAlgorithm {
|
||||
// if running sum is negative then it is initialized to zero
|
||||
}
|
||||
// for-each loop is used to iterate over the array and find the maximum subarray sum
|
||||
return sum == predicted_answer;
|
||||
return sum == predictedAnswer;
|
||||
// It returns true if sum and predicted answer matches
|
||||
// The predicted answer is the answer itself. So it always return true
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public final class NewManShanksPrime {
|
||||
private NewManShanksPrime() {
|
||||
}
|
||||
|
||||
public static boolean nthManShanksPrime(int n, int expected_answer) {
|
||||
public static boolean nthManShanksPrime(int n, int expectedAnswer) {
|
||||
int[] a = new int[n + 1];
|
||||
// array of n+1 size is initialized
|
||||
a[0] = 1;
|
||||
@ -22,7 +22,7 @@ public final class NewManShanksPrime {
|
||||
a[i] = 2 * a[i - 1] + a[i - 2];
|
||||
}
|
||||
// The loop is continued till n
|
||||
return a[n] == expected_answer;
|
||||
return a[n] == expectedAnswer;
|
||||
// returns true if calculated answer matches with expected answer
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,16 @@ public final class SumOfSubset {
|
||||
private SumOfSubset() {
|
||||
}
|
||||
|
||||
public static boolean subsetSum(int[] arr, int num, int Key) {
|
||||
if (Key == 0) {
|
||||
public static boolean subsetSum(int[] arr, int num, int key) {
|
||||
if (key == 0) {
|
||||
return true;
|
||||
}
|
||||
if (num < 0 || Key < 0) {
|
||||
if (num < 0 || key < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean include = subsetSum(arr, num - 1, Key - arr[num]);
|
||||
boolean exclude = subsetSum(arr, num - 1, Key);
|
||||
boolean include = subsetSum(arr, num - 1, key - arr[num]);
|
||||
boolean exclude = subsetSum(arr, num - 1, key);
|
||||
|
||||
return include || exclude;
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ public final class Convolution {
|
||||
* signal must start from 0. If you have a signal that has values before 0
|
||||
* then shift it to start from 0.
|
||||
*
|
||||
* @param A The first discrete signal
|
||||
* @param B The second discrete signal
|
||||
* @param a The first discrete signal
|
||||
* @param b The second discrete signal
|
||||
* @return The convolved signal
|
||||
*/
|
||||
public static double[] convolution(double[] A, double[] B) {
|
||||
double[] convolved = new double[A.length + B.length - 1];
|
||||
public static double[] convolution(double[] a, double[] b) {
|
||||
double[] convolved = new double[a.length + b.length - 1];
|
||||
|
||||
/*
|
||||
The discrete convolution of two signals A and B is defined as:
|
||||
@ -35,10 +35,10 @@ public final class Convolution {
|
||||
*/
|
||||
for (int i = 0; i < convolved.length; i++) {
|
||||
convolved[i] = 0;
|
||||
int k = Math.max(i - B.length + 1, 0);
|
||||
int k = Math.max(i - b.length + 1, 0);
|
||||
|
||||
while (k < i + 1 && k < A.length) {
|
||||
convolved[i] += A[k] * B[i - k];
|
||||
while (k < i + 1 && k < a.length) {
|
||||
convolved[i] += a[k] * b[i - k];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
@ -6,34 +6,34 @@ public final class Gaussian {
|
||||
private Gaussian() {
|
||||
}
|
||||
|
||||
public static ArrayList<Double> gaussian(int mat_size, ArrayList<Double> matrix) {
|
||||
public static ArrayList<Double> gaussian(int matSize, ArrayList<Double> matrix) {
|
||||
ArrayList<Double> answerArray = new ArrayList<Double>();
|
||||
int i;
|
||||
int j = 0;
|
||||
|
||||
double[][] mat = new double[mat_size + 1][mat_size + 1];
|
||||
double[][] x = new double[mat_size][mat_size + 1];
|
||||
double[][] mat = new double[matSize + 1][matSize + 1];
|
||||
double[][] x = new double[matSize][matSize + 1];
|
||||
|
||||
// Values from arraylist to matrix
|
||||
for (i = 0; i < mat_size; i++) {
|
||||
for (j = 0; j <= mat_size; j++) {
|
||||
for (i = 0; i < matSize; i++) {
|
||||
for (j = 0; j <= matSize; j++) {
|
||||
mat[i][j] = matrix.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
mat = gaussianElimination(mat_size, i, mat);
|
||||
answerArray = valueOfGaussian(mat_size, x, mat);
|
||||
mat = gaussianElimination(matSize, i, mat);
|
||||
answerArray = valueOfGaussian(matSize, x, mat);
|
||||
return answerArray;
|
||||
}
|
||||
|
||||
// Perform Gaussian elimination
|
||||
public static double[][] gaussianElimination(int mat_size, int i, double[][] mat) {
|
||||
public static double[][] gaussianElimination(int matSize, int i, double[][] mat) {
|
||||
int step = 0;
|
||||
for (step = 0; step < mat_size - 1; step++) {
|
||||
for (i = step; i < mat_size - 1; i++) {
|
||||
for (step = 0; step < matSize - 1; step++) {
|
||||
for (i = step; i < matSize - 1; i++) {
|
||||
double a = (mat[i + 1][step] / mat[step][step]);
|
||||
|
||||
for (int j = step; j <= mat_size; j++) {
|
||||
for (int j = step; j <= matSize; j++) {
|
||||
mat[i + 1][j] = mat[i + 1][j] - (a * mat[step][j]);
|
||||
}
|
||||
}
|
||||
@ -42,27 +42,27 @@ public final class Gaussian {
|
||||
}
|
||||
|
||||
// calculate the x_1, x_2, ... values of the gaussian and save it in an arraylist.
|
||||
public static ArrayList<Double> valueOfGaussian(int mat_size, double[][] x, double[][] mat) {
|
||||
public static ArrayList<Double> valueOfGaussian(int matSize, double[][] x, double[][] mat) {
|
||||
ArrayList<Double> answerArray = new ArrayList<Double>();
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < mat_size; i++) {
|
||||
for (j = 0; j <= mat_size; j++) {
|
||||
for (i = 0; i < matSize; i++) {
|
||||
for (j = 0; j <= matSize; j++) {
|
||||
x[i][j] = mat[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = mat_size - 1; i >= 0; i--) {
|
||||
for (i = matSize - 1; i >= 0; i--) {
|
||||
double sum = 0;
|
||||
for (j = mat_size - 1; j > i; j--) {
|
||||
for (j = matSize - 1; j > i; j--) {
|
||||
x[i][j] = x[j][j] * x[i][j];
|
||||
sum = x[i][j] + sum;
|
||||
}
|
||||
if (x[i][i] == 0) {
|
||||
x[i][i] = 0;
|
||||
} else {
|
||||
x[i][i] = (x[i][mat_size] - sum) / (x[i][i]);
|
||||
x[i][i] = (x[i][matSize] - sum) / (x[i][i]);
|
||||
}
|
||||
answerArray.add(x[i][j]);
|
||||
}
|
||||
|
@ -17,14 +17,14 @@ public final class PronicNumber {
|
||||
/**
|
||||
* This method checks if the given number is pronic number or non-pronic number
|
||||
*
|
||||
* @param input_number Integer value which is to be checked if is a pronic number or not
|
||||
* @param inputNumber Integer value which is to be checked if is a pronic number or not
|
||||
* @return true if input number is a pronic number, false otherwise
|
||||
*/
|
||||
static boolean isPronic(int input_number) {
|
||||
static boolean isPronic(int inputNumber) {
|
||||
// Iterating from 0 to input_number
|
||||
for (int i = 0; i <= input_number; i++) {
|
||||
for (int i = 0; i <= inputNumber; i++) {
|
||||
// Checking if product of i and (i+1) is equals input_number
|
||||
if (i * (i + 1) == input_number && i != input_number) {
|
||||
if (i * (i + 1) == inputNumber && i != inputNumber) {
|
||||
// return true if product of i and (i+1) is equals input_number
|
||||
return true;
|
||||
}
|
||||
|
@ -55,14 +55,14 @@ public class VectorCrossProduct {
|
||||
/**
|
||||
* constructor, initialises Vector with given Direction Ratios
|
||||
*
|
||||
* @param _x set to x
|
||||
* @param _y set to y
|
||||
* @param _z set to z
|
||||
* @param vectorX set to x
|
||||
* @param vectorY set to y
|
||||
* @param vectorZ set to z
|
||||
*/
|
||||
VectorCrossProduct(int _x, int _y, int _z) {
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
VectorCrossProduct(int vectorX, int vectorY, int vectorZ) {
|
||||
x = vectorX;
|
||||
y = vectorY;
|
||||
z = vectorZ;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,17 +39,17 @@ public final class KMP {
|
||||
}
|
||||
|
||||
// return the prefix function
|
||||
private static int[] computePrefixFunction(final String P) {
|
||||
final int n = P.length();
|
||||
private static int[] computePrefixFunction(final String p) {
|
||||
final int n = p.length();
|
||||
final int[] pi = new int[n];
|
||||
pi[0] = 0;
|
||||
int q = 0;
|
||||
for (int i = 1; i < n; i++) {
|
||||
while (q > 0 && P.charAt(q) != P.charAt(i)) {
|
||||
while (q > 0 && p.charAt(q) != p.charAt(i)) {
|
||||
q = pi[q - 1];
|
||||
}
|
||||
|
||||
if (P.charAt(q) == P.charAt(i)) {
|
||||
if (p.charAt(q) == p.charAt(i)) {
|
||||
q++;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ final class PasswordGen {
|
||||
private PasswordGen() {
|
||||
}
|
||||
|
||||
static String generatePassword(int min_length, int max_length) {
|
||||
static String generatePassword(int minLength, int maxLength) {
|
||||
Random random = new Random();
|
||||
|
||||
String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
@ -35,7 +35,7 @@ final class PasswordGen {
|
||||
StringBuilder password = new StringBuilder();
|
||||
|
||||
// Note that size of the password is also random
|
||||
for (int i = random.nextInt(max_length - min_length) + min_length; i > 0; --i) {
|
||||
for (int i = random.nextInt(maxLength - minLength) + minLength; i > 0; --i) {
|
||||
password.append(letters.get(random.nextInt(letters.size())));
|
||||
}
|
||||
|
||||
|
@ -83,28 +83,28 @@ public class SJFScheduling {
|
||||
/**
|
||||
* this function evaluates the shortest job of all the ready processes (based on a process
|
||||
* burst time)
|
||||
* @param ReadyProcesses an array list of ready processes
|
||||
* @param readyProcesses an array list of ready processes
|
||||
* @return returns the process' with the shortest burst time OR NULL if there are no ready
|
||||
* processes
|
||||
*/
|
||||
private ProcessDetails findShortestJob(ArrayList<ProcessDetails> ReadyProcesses) {
|
||||
if (ReadyProcesses.isEmpty()) {
|
||||
private ProcessDetails findShortestJob(ArrayList<ProcessDetails> readyProcesses) {
|
||||
if (readyProcesses.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int i;
|
||||
int size = ReadyProcesses.size();
|
||||
int minBurstTime = ReadyProcesses.get(0).getBurstTime();
|
||||
int size = readyProcesses.size();
|
||||
int minBurstTime = readyProcesses.get(0).getBurstTime();
|
||||
int temp;
|
||||
int positionOfShortestJob = 0;
|
||||
|
||||
for (i = 1; i < size; i++) {
|
||||
temp = ReadyProcesses.get(i).getBurstTime();
|
||||
temp = readyProcesses.get(i).getBurstTime();
|
||||
if (minBurstTime > temp) {
|
||||
minBurstTime = temp;
|
||||
positionOfShortestJob = i;
|
||||
}
|
||||
}
|
||||
|
||||
return ReadyProcesses.get(positionOfShortestJob);
|
||||
return readyProcesses.get(positionOfShortestJob);
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +55,8 @@ public class BitonicSort {
|
||||
|
||||
/*Caller of bitonicSort for sorting the entire array
|
||||
of length N in ASCENDING order */
|
||||
void sort(int[] a, int N, int up) {
|
||||
bitonicSort(a, 0, N, up);
|
||||
void sort(int[] a, int n, int up) {
|
||||
bitonicSort(a, 0, n, up);
|
||||
}
|
||||
|
||||
/* A utility function to print array of size n */
|
||||
|
Reference in New Issue
Block a user