New answers tagged algorithm
5
votes
A Java program for compressing/decompressing files via Huffman algorithms (version 1.0.0)
Multiple aspects of this implementation of a Huffman encoder and decoder are inefficient.
At the top level, a bit-by-bit tree-walking decoder is inherently slow. Almost every practical decoder uses ...
2
votes
Binary Search Tree implementation in C [1]
Style
You mix braces and not using braces freely throughout your code. While this works, it leaves open the possibility of adding to branches of conditionals or to loops and forgetting to add braces, ...
3
votes
Huffman code builder in Java - computing prefix codes for arbitrary (generic) alphabets - Take II
The HuffmanEncoder is not an encoder. It's a builder that constructs the code table for the symbols based on the weights. An encoder would take input and encode it ...
4
votes
Shortest Cell Path In a given grid
Style
Let's look at this conditional in shortestCellPathHelper.
...
3
votes
HuffmannEncoder.java - computing prefix codes for arbitrary (generic) alphabets
Minor but, Huffman only has a single n in the name.
But let's move on to how the code words are built, the meat of the algorithm after all.
...
3
votes
HuffmannEncoder.java - computing prefix codes for arbitrary (generic) alphabets
Style
When I look at your formatting in the following snippet, for some reason you have a newline after the first argument to Double.compare, but this line would be ...
6
votes
LeetCode 3542: Minimum Operations to Convert All Elements to Zero
missing docstring
def split_non_zeros(self, nums):
This is terrible.
The identifier is not bad, as far as it goes.
But we need to know what the function ...
6
votes
Accepted
LeetCode 3542: Minimum Operations to Convert All Elements to Zero
Style
First off, let's address a couple of style issues.
Looping over indices of a list is better achieved with enumerate than with ...
3
votes
LeetCode 3542: Minimum Operations to Convert All Elements to Zero
Simpler
Here are some general coding style suggestions.
The following:
counter = counter + 1
can be simplified using the special assignment operator:
...
4
votes
Jump point search in Java for faster pathfinding in grid mazes
To handle diagonal moves that cross walls, you need to relax the corner-blocking logic in both the jumper and the neighbour finder.
Right now, your ...
1
vote
Shortest Cell Path In a given grid
I realize you created this code as quickly as possible for an interview,
and your main focus was functionality. Here are some general coding style
suggestions.
Indentation
In the ...
3
votes
A simple method for compressing white space in text (Java) - Take II
Just some remarks.
By providing a capacity: new StringBuilder(textLength) - here a bit extra room, you prevent internal array resizing inside StringBuilder. For ...
1
vote
Computing loan cuts leading to a global zero equity in a financial graph (Java)
Comparing to false
In more than one place you have code like the following. You should never need to explicitly compare a boolean value to ...
2
votes
Benchmarking in Java some super linearithmic sorting algorithms
(I acknowledge title&introduction read benchmarking and comparison.
(I suggest to think compare implementations of several algorithms rather than compare several algorithms.)
For now going neither ...
5
votes
A simple method for compressing white space in text (Java) - Take II
Readable. (A big plus in my book.)
Verbose. I find what benefits I see unconvincing.
(Given the ease of copies, the typo // Scan empty suffix is any: is strange.)
I'...
6
votes
Accepted
Benchmarking in Java some super linearithmic sorting algorithms
I think the key issue is to make sure you're gathering sufficient information. You're timing one call of each method and using that to compare them. I would suggest you call each method many times1, ...
6
votes
Accepted
A simple method for compressing white space in text (Java) - Take II
For exhaustiveness, I'd probably suggest your test if loIndex equals hiIndex should test to see if the former is greater than or ...
8
votes
Accepted
A simple method for compressing white space in text (Java)
Simplicity
It strikes me that the simplest method to do this is to leverage the standard library. You will want to learn how to use regular expressions. Your effort will be rewarded.
...
3
votes
ShannonFanoEncoder.java - computing prefix codes in Java
Your algorithm is definitely more readable and has better naming than the java version in the web. However there still seems to be room for improvement.
To offer a comparison, I did the Shannon-Fano ...
Top 50 recent answers are included
Related Tags
algorithm × 5128java × 1301
python × 1210
performance × 1013
c++ × 855
programming-challenge × 665
javascript × 488
c# × 401
strings × 359
c × 336
python-3.x × 324
sorting × 323
beginner × 306
graph × 260
time-limit-exceeded × 257
array × 249
tree × 213
recursion × 177
interview-questions × 169
python-2.x × 164
combinatorics × 134
complexity × 134
mathematics × 112
pathfinding × 103
c++11 × 101