Skip to content

update from forks #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
40620ae
To find sum of triplets according to given value
joshiujjawal22 May 18, 2020
c0eb73a
Rotation of an array without using extra space
joshiujjawal22 May 18, 2020
63b9e13
Create BucketSort.java
THE-VR7 May 21, 2020
227dd31
Merge pull request #1 from THE-VR7/THE-VR7-patch-1
THE-VR7 May 21, 2020
627115b
Created Graph Algos
Ritik2604 May 22, 2020
278529e
Create SinglyLinkedList
Ritik2604 May 23, 2020
4842a4c
Update and rename SinglyLinkedList to ListAddnFun
Ritik2604 May 23, 2020
ef2be07
Create AVLSimple
Ritik2604 May 23, 2020
07aee8b
Create BoardPath
Ritik2604 May 23, 2020
e717f96
Create CountNumBinaryStrings
Ritik2604 May 23, 2020
9a8ccea
Delete LinkedList.java
Ritik2604 May 23, 2020
3a234f0
Delete Node.java
Ritik2604 May 23, 2020
01d5814
Create Intersection
Ritik2604 May 23, 2020
ed497ce
Update BucketSort.java
THE-VR7 May 23, 2020
1ef46db
Update GraphAlgos
Ritik2604 May 24, 2020
a5f42e2
Fixed Error:(6, 8) java: class algorithm is public, should be declare…
May 24, 2020
f710f3a
Update ListAddnFun
Ritik2604 May 24, 2020
82e2132
Update AVLSimple
Ritik2604 May 24, 2020
920852a
Update BoardPath
Ritik2604 May 24, 2020
94cfab0
Update BoardPath
Ritik2604 May 24, 2020
ec4f6a1
Update CountNumBinaryStrings
Ritik2604 May 24, 2020
a23a17b
Update Intersection
Ritik2604 May 24, 2020
c76c4dd
Update CONTRIBUTING.md file
MohamedBechir May 24, 2020
d342c2d
Merge pull request #1322 from Ritik2604/master
deadshotsb May 25, 2020
91b9ac7
updating DIRECTORY.md
May 25, 2020
8b6415f
Update CONTRIBUTION.md
deadshotsb May 25, 2020
c37257c
Merge pull request #1326 from MohamedBechir/patch-1
deadshotsb May 25, 2020
88c6ad9
Merge pull request #1325 from mariaRoxana94/fix-error
StepfenShawn May 28, 2020
3b52109
Added test cases
joshiujjawal22 May 29, 2020
65dcfd9
Merge pull request #1316 from joshiujjawal22/master
deadshotsb May 29, 2020
a6398d1
updating DIRECTORY.md
May 29, 2020
de85372
Merge pull request #1321 from THE-VR7/master
StepfenShawn Jun 1, 2020
e3a78a6
updating DIRECTORY.md
Jun 1, 2020
b1caf8c
Minimum sum partition
swatiprajapati08 Jun 1, 2020
5d77174
Update Minimum sum partition
swatiprajapati08 Jun 3, 2020
4ac4a62
Merge pull request #1338 from swatiprajapati08/patch-1
deadshotsb Jun 3, 2020
7179718
Update ParseInteger.java
lollerfirst Jun 9, 2020
88d65ff
Merge pull request #1347 from lollerfirst/patch-1, close #1345
yanglbme Jun 12, 2020
1553639
marcosvillacanas-A-Star
MarcosVillacanas Jun 12, 2020
ce945bc
Complexity Added
MarcosVillacanas Jun 12, 2020
dd06589
Kruskal Algorithm Implemented
MarcosVillacanas Jun 17, 2020
c21ae9a
Graph Initialization outside private classes
MarcosVillacanas Jun 19, 2020
5150a6b
Closed Scanner in 3 sum, fixed syntax errors in BucketSort.java
hardik-kapadia Jun 29, 2020
d07e668
Fixed <T> parameter error in SelectionSort
hardik-kapadia Jun 29, 2020
95389bf
Fixed wrong order in BubbleSort, corrected spelling mistakes
Jun 30, 2020
4b42784
Merge pull request #1357 from astralcake/master
StepfenShawn Jul 4, 2020
bf0fdd7
Context added
MarcosVillacanas Jul 6, 2020
174b43c
link-Removed
MarcosVillacanas Jul 6, 2020
0c43428
Merge pull request #1354 from thecoderenroute/master
StepfenShawn Jul 7, 2020
d7a6796
Merge pull request #1352 from MarcosVillacanas/marcosvillacanas-kruskal
deadshotsb Jul 7, 2020
6f0ea8d
updating DIRECTORY.md
Jul 7, 2020
4e058de
Update README.md
StepfenShawn Jul 8, 2020
7a4d6b2
z function added
vakhokoto Jul 10, 2020
a63cb70
Merge pull request #1350 from MarcosVillacanas/marcosvillacanas-A-Star
AnupKumarPanwar Jul 16, 2020
b8fa504
updating DIRECTORY.md
Jul 16, 2020
a983a15
description added and also link to the algorithm review
vakhokoto Jul 22, 2020
8bb54ca
Merge pull request #1362 from vakhokoto/z-function
deadshotsb Jul 22, 2020
5e8c8c7
updating DIRECTORY.md
Jul 22, 2020
6e7a326
Revert "z function added"
deadshotsb Jul 22, 2020
c4a8f71
updating DIRECTORY.md
Jul 22, 2020
d2870c8
Merge pull request #1365 from TheAlgorithms/revert-1362-z-function
deadshotsb Jul 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
## Contribution Guidelines
Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
:+1::tada: Before guiding you through the contribution process TheAlgorithms/Java thank you for being one of us! :+1::tada:

## How to contribute?

#### **Did you find a bug?**

* **Ensure the bug was not already reported** by searching on GitHub under [Project Issues](https://github.com/TheAlgorithms/Java/issues).

* Please avoid opening issues asking to be "assigned” to a particular algorithm. This merely creates unnecessary noise for maintainers. Instead, please submit your implementation in a pull request and it will be evaluated by project maintainers.

* If you are unable to find an open issue refering to the same problem, depending on the type of issue follow the appropriate steps:

#### **Do you want to contribute to the documentation?**

* Please read the documentation in here [Contributing to the Documentation]() ,[open a new one issue](https://github.com/TheAlgorithms/Java/issues/new), make changes and then create a pull request, it will be put under review and accepted if it is approprite.

#### **Do you want to add a new feature?**
* [Open a new one issue](https://github.com/TheAlgorithms/Java/issues/new). Be sure to include a **title and a clear description** and a **test case** demonstrating the new feature that you want to add to the project.

#### **Do you want to fix a bug?**
* [Open a new one issue](https://github.com/TheAlgorithms/Java/issues/new).Be sure to include a **title and a clear description** and a **test case** demonstrating the expected behaviour that is not occuring.

#### **Do you have questions about the source code?**

* Ask any question about how to use the repository in the [TheAlgorithms room in GITTER](https://gitter.im/TheAlgorithms/community?source=orgpage#) or [open a new one issue](https://github.com/TheAlgorithms/Java/issues/new)

:+1::tada: That's all you need to know about the process now it's your turn to help us improve the repository, thank you again! :+1::tada:
4 changes: 2 additions & 2 deletions Conversions/DecimalToBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void main(String args[]) {
public static void conventionalConversion() {
int n, b = 0, c = 0, d;
Scanner input = new Scanner(System.in);
System.out.printf("Conventional conversion.\n\tEnter the decimal number: ");
System.out.printf("Conventional conversion.%n Enter the decimal number: ");
n = input.nextInt();
while (n != 0) {
d = n % 2;
Expand All @@ -46,7 +46,7 @@ public static void conventionalConversion() {
public static void bitwiseConversion() {
int n, b = 0, c = 0, d;
Scanner input = new Scanner(System.in);
System.out.printf("Bitwise conversion.\n\tEnter the decimal number: ");
System.out.printf("Bitwise conversion.%n Enter the decimal number: ");
n = input.nextInt();
while (n != 0) {
d = (n & 1);
Expand Down
8 changes: 4 additions & 4 deletions Conversions/OctalToHexadecimal.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class OctalToHexadecimal {
* @param s The Octal Number
* @return The Decimal number
*/
public static int OctToDec(String s) {
public static int octToDec(String s) {
int i = 0;
for (int j = 0; j < s.length(); j++) {
char num = s.charAt(j);
Expand All @@ -32,7 +32,7 @@ public static int OctToDec(String s) {
* @param d The Decimal Number
* @return The Hexadecimal number
*/
public static String DecimalToHex(int d) {
public static String decimalToHex(int d) {
String digits = "0123456789ABCDEF";
if (d <= 0)
return "0";
Expand All @@ -54,10 +54,10 @@ public static void main(String args[]) {
String oct = input.next();

// Pass the octal number to function and get converted deciaml form
int decimal = OctToDec(oct);
int decimal = octToDec(oct);

// Pass the decimla number to function and get converted Hex form of the number
String hex = DecimalToHex(decimal);
String hex = decimalToHex(decimal);
System.out.println("The Hexadecimal equivalant is: " + hex);
input.close();
}
Expand Down
7 changes: 5 additions & 2 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@
* DynamicArray
* [DynamicArray](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/DynamicArray/DynamicArray.java)
* Graphs
* [A Star](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Graphs/A_Star.java)
* [BellmanFord](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Graphs/BellmanFord.java)
* [ConnectedComponent](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Graphs/ConnectedComponent.java)
* [Cycles](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Graphs/Cycles.java)
* [FloydWarshall](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Graphs/FloydWarshall.java)
* [Graphs](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Graphs/Graphs.java)
* [Kruskal](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Graphs/Kruskal.java)
* [MatrixGraphs](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Graphs/MatrixGraphs.java)
* [PrimMST](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Graphs/PrimMST.java)
* HashMap
* Hashing
* [HashMap](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/HashMap/Hashing/HashMap.java)
* [LinkedList](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/HashMap/Hashing/LinkedList.java)
* [Main](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/HashMap/Hashing/Main.java)
* [Node](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/HashMap/Hashing/Node.java)
* Heaps
* [EmptyHeapException](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Heaps/EmptyHeapException.java)
* [Heap](https://github.com/TheAlgorithms/Java/blob/master/DataStructures/Heaps/Heap.java)
Expand Down Expand Up @@ -139,6 +139,7 @@
* [PalindromePrime](https://github.com/TheAlgorithms/Java/blob/master/Misc/PalindromePrime.java)

## Others
* [3 sum](https://github.com/TheAlgorithms/Java/blob/master/Others/3%20sum.java)
* [Abecedarian](https://github.com/TheAlgorithms/Java/blob/master/Others/Abecedarian.java)
* [Armstrong](https://github.com/TheAlgorithms/Java/blob/master/Others/Armstrong.java)
* [BestFit](https://github.com/TheAlgorithms/Java/blob/master/Others/BestFit.java)
Expand Down Expand Up @@ -169,6 +170,7 @@
* [ReverseStackUsingRecursion](https://github.com/TheAlgorithms/Java/blob/master/Others/ReverseStackUsingRecursion.java)
* [ReverseString](https://github.com/TheAlgorithms/Java/blob/master/Others/ReverseString.java)
* [RootPrecision](https://github.com/TheAlgorithms/Java/blob/master/Others/RootPrecision.java)
* [Rotation of array without using extra space](https://github.com/TheAlgorithms/Java/blob/master/Others/Rotation%20of%20array%20without%20using%20extra%20space.java)
* [SieveOfEratosthenes](https://github.com/TheAlgorithms/Java/blob/master/Others/SieveOfEratosthenes.java)
* [SJF](https://github.com/TheAlgorithms/Java/blob/master/Others/SJF.java)
* [SkylineProblem](https://github.com/TheAlgorithms/Java/blob/master/Others/SkylineProblem.java)
Expand All @@ -193,6 +195,7 @@
* [BitonicSort](https://github.com/TheAlgorithms/Java/blob/master/Sorts/BitonicSort.java)
* [BogoSort](https://github.com/TheAlgorithms/Java/blob/master/Sorts/BogoSort.java)
* [BubbleSort](https://github.com/TheAlgorithms/Java/blob/master/Sorts/BubbleSort.java)
* [BucketSort](https://github.com/TheAlgorithms/Java/blob/master/Sorts/BucketSort.java)
* [CocktailShakerSort](https://github.com/TheAlgorithms/Java/blob/master/Sorts/CocktailShakerSort.java)
* [CombSort](https://github.com/TheAlgorithms/Java/blob/master/Sorts/CombSort.java)
* [CountingSort](https://github.com/TheAlgorithms/Java/blob/master/Sorts/CountingSort.java)
Expand Down
4 changes: 2 additions & 2 deletions DataStructures/DynamicArray/DynamicArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void add(final E element) {
}

public void put(final int index, E element) {
Objects.checkIndex(index, this.size);
// Objects.checkIndex(index, this.size);

this.elements[index] = element;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ private void fastRemove(final Object[] elements, final int index) {
}

private E getElement(final int index) {
Objects.checkIndex(index, this.size);
// Objects.checkIndex(index, this.size);
return (E) this.elements[index];
}

Expand Down
159 changes: 159 additions & 0 deletions DataStructures/Graphs/A_Star.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
Time Complexity = O(E), where E is equal to the number of edges
*/

package A_Star;

import java.util.*;

public class A_Star {

private static class Graph {
//Graph's structure can be changed only applying changes to this class.
private ArrayList<Edge> [] graph;

//Initialise ArrayLists in Constructor
public Graph(int size) {
this.graph = new ArrayList[size];
for (int i = 0; i < size; i++) {
this.graph[i] = new ArrayList<>();
}
}

private ArrayList<Edge> getNeighbours(int from) { return this.graph[from]; }

//Graph is bidirectional, for just one direction remove second instruction of this method.
private void addEdge (Edge edge) {
this.graph[edge.getFrom()].add(new Edge(edge.getFrom(), edge.getTo(), edge.getWeight()));
this.graph[edge.getTo()].add(new Edge(edge.getTo(), edge.getFrom(), edge.getWeight()));
}
}

private static class Edge {
private int from;
private int to;
private int weight;

public Edge(int from, int to, int weight) {
this.from = from;
this.to = to;
this.weight = weight;
}

public int getFrom() { return from; }

public int getTo() { return to; }

public int getWeight() { return weight; }
}

//class to iterate during the algorithm execution, and also used to return the solution.
private static class PathAndDistance {
private int distance; //distance advanced so far.
private ArrayList<Integer> path; //list of visited nodes in this path.
private int estimated; //heuristic value associated to the last node od the path (current node).

public PathAndDistance(int distance, ArrayList<Integer> path, int estimated) {
this.distance = distance;
this.path = path;
this.estimated = estimated;
}

public int getDistance() { return distance; }

public ArrayList<Integer> getPath() { return path; }

public int getEstimated() { return estimated; }

private void printSolution () {
if (this.path != null)
System.out.println("Optimal path: " + this.path.toString() +
", distance: " + this.distance);
else
System.out.println("There is no path available to connect the points");
}
}

private static void initializeGraph(Graph graph, ArrayList<Integer> data) {
for (int i = 0; i < data.size(); i+=4) {
graph.addEdge(new Edge(data.get(i), data.get(i + 1), data.get(i + 2)));
}
/*
.x. node
(y) cost
- or | or / bidirectional connection

( 98)- .7. -(86)- .4.
|
( 85)- .17. -(142)- .18. -(92)- .8. -(87)- .11.
|
. 1. -------------------- (160)
| \ |
(211) \ .6.
| \ |
. 5. (101)-.13. -(138) (115)
| | | /
( 99) ( 97) | /
| | | /
.12. -(151)- .15. -(80)- .14. | /
| | | | /
( 71) (140) (146)- .2. -(120)
| | |
.19. -( 75)- . 0. .10. -(75)- .3.
| |
(118) ( 70)
| |
.16. -(111)- .9.
*/
}

public static void main(String[] args) {
//heuristic function optimistic values
int[] heuristic = {366, 0, 160, 242, 161, 178, 77, 151, 226,
244, 241, 234, 380, 98, 193, 253, 329, 80, 199, 374};

Graph graph = new Graph(20);
ArrayList<Integer> graphData = new ArrayList<>(Arrays.asList(0, 19, 75, null,
0, 15, 140, null, 0, 16, 118, null, 19, 12, 71, null, 12, 15, 151, null,
16, 9, 111, null, 9, 10, 70, null, 10, 3, 75, null, 3, 2, 120, null,
2, 14, 146, null, 2, 13, 138, null, 2, 6, 115, null, 15, 14, 80, null,
15, 5, 99, null, 14, 13, 97, null, 5, 1, 211, null, 13, 1, 101, null,
6, 1, 160, null, 1, 17, 85, null, 17, 7, 98, null, 7, 4, 86, null,
17, 18, 142, null, 18, 8, 92, null, 8, 11, 87));
initializeGraph(graph, graphData);

PathAndDistance solution = aStar(3, 1, graph, heuristic);
solution.printSolution();

}

public static PathAndDistance aStar(int from, int to, Graph graph, int[] heuristic) {
//nodes are prioritised by the less value of the current distance of their paths, and the estimated value
//given by the heuristic function to reach the destination point from the current point.
PriorityQueue<PathAndDistance> queue = new PriorityQueue<>
(Comparator.comparingInt(a -> (a.getDistance() + a.getEstimated())));

//dummy data to start the algorithm from the beginning point
queue.add(new PathAndDistance(0, new ArrayList<>(Arrays.asList(from)), 0));

boolean solutionFound = false;
PathAndDistance currentData = new PathAndDistance(-1, null, -1);
while (!queue.isEmpty() && !solutionFound) {
currentData = queue.poll(); //first in the queue, best node so keep exploring.
int currentPosition = currentData.getPath().get(currentData.getPath().size() - 1); //current node.
if (currentPosition == to)
solutionFound = true;
else
for (Edge edge : graph.getNeighbours(currentPosition))
if (!currentData.getPath().contains(edge.getTo())) { //Avoid Cycles
ArrayList<Integer> updatedPath = new ArrayList<>(currentData.getPath());
updatedPath.add(edge.getTo()); //Add the new node to the path, update the distance,
// and the heuristic function value associated to that path.
queue.add(new PathAndDistance(currentData.getDistance() + edge.getWeight(),
updatedPath, heuristic[edge.getTo()]));
}
}
return (solutionFound) ? currentData : new PathAndDistance(-1, null, -1);
//Out of while loop, if there is a solution, the current Data stores the optimal path, and its distance
}
}
2 changes: 1 addition & 1 deletion DataStructures/Graphs/BellmanFord.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Edge
* @param v End vertex
* @param c Weight
*/
Edge(int a,int b,int c)
public Edge(int a,int b,int c)
{
u=a;
v=b;
Expand Down
Loading