pedrovgs / algorithms Goto Github PK
View Code? Open in Web Editor NEWSolutions for some common algorithm problems written in Java.
License: Apache License 2.0
Solutions for some common algorithm problems written in Java.
License: Apache License 2.0
I guess package names should not contain anything as meaningless as "problem65". The greatest virtue of today's world is a code reuse. I would like to import code from something with a descriptive name so as not to confuse my followers.
Why isn't it called package com.github.pedrovgs.algorithms.IsTreeBalanced
?
Hi,
I have two questions, and don't know how to contact you except raising issue. :)
1st
How do I create a repo with all comit history preserved, with all codes in just main and test package. I tried doing that in https://github.com/ajinkyakolhe112/JavaAlgorithms
2nd
I am giving you full credit for the code. So I am allowed to do this right?
Thanks.
Hi,
Is there really a class "FakeFile" ? Because File has not getLine() method ?
That's for RemoveComments.java / line 46 and 65 ?
In the sorting quick sort is not there.So can I send PR.
Is there any coding style to follow?
int[] lettersA = getLettersAsArray(a);
int[] lettersB = getLettersAsArray(b);
lettersA and lettersB must have the same content. not same count.
if the first line is :
1/*/123
it will have an error
It would be helpful for you to add Karatsuba as it is used to get fastest multiplication.
The Anagrams algorithm is wrong. Consider the following test case:
public class AreAnagramsTest {
@Test
public void check() throws Exception {
AreAnagrams areAnagrams = new AreAnagrams();
assertFalse(areAnagrams.check("abc", "efg"));
}
}
You cannot use sums of the values. You need to compare whether you have enough characters in each array one by one.
This variable could be defined as:
private int index;
and placed above the methods
Please have a try with the following test using JUnit, it will fail with timeout
.
Please hold a sec, I am starting a PR for this along with tests later (today).
public class QuickSortGitTest {
private static final int[] unorderedIntegerArrayThree = {12, -37, -5, 43, 62, 45, -95, -70, -55, -62, -24, -14,
-75, 43, 9, 58, -62, -22, -55};
private static void quickSort(int[] numbers, int left, int right) {
if (left < right) {
int pivotIndex = partition(numbers, left, right);
quickSort(numbers, left, pivotIndex - 1); //sort left of pivot
quickSort(numbers, pivotIndex, right); //sort right of pivot
}
}
// private static int partition(int[] array, int low, int high) {
// int pivot = array[high];
// int i = low - 1;
// for (int j = low; j <= high - 1; j++)
// if (array[j] <= pivot)
// swap(array, ++i, j);
//
// swap(array, i + 1, high);
// return i + 1;
// }
//
// private static void swap(int[] array, int i, int j) {
// int temp;
// temp = array[i];
// array[i] = array[j];
// array[j] = temp;
// }
private static int partition(int[] numbers, int left, int right) {
int pivot = numbers[right];
while (left < right) {
while (numbers[left] < pivot) {
left++;
}
while (numbers[right] > pivot) {
right--;
}
if (left <= right) {
int temp = numbers[left];
numbers[left] = numbers[right];
numbers[right] = temp;
}
}
return left; //pivot index
}
@Test(timeout = 5 * 1000)
public void testRecursionZero() {
quickSort(unorderedIntegerArrayThree, 0, unorderedIntegerArrayThree.length - 1);
}
}
I'm a senior student from China and i'm learning Java in recent days.I think your project is cool,so I wanna to add some comments in chinese to improve my schoolmates and myself.
Why it should cause a exception when there is a element in the tree and the position is 1?
it should return the element whose index is position-1, isn't it?
https://github.com/pedrovgs/Algorithms/blob/master/src/main/java/com/github/pedrovgs/problem44/FindMinNumberAtPosition.java#L52
I think this line should be:
if (position > orderedElements.size()) {
or you can't get the last element in the tree
Can i contribute to this repo? E.G add more sorting algorithms etc?
Disclaimer: noob
When I type javac Trie.java I get this output
Trie.java:5: error: package com.jwetherell.algorithms.data_structures.interfaces does not exist
import com.jwetherell.algorithms.data_structures.interfaces.ITree
I read your code and I don't think the bubble sort is like what I read from the algorithm books. I don't get it. The comment says 'compares each pair of adjacent items and swaps them if they are in the wrong order',but it is not. The code is compare the elment to the others every step(not adjacent ones). It works but it is not as the comment says.
Line 62 should be
if (x < 0 || y < 0 || x >= picture.length || y >= picture[x].length) {
I just happen here in your repo and work is pretty much nice.
Can I give one suggestion about content structure readme file?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.