Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >

New answers tagged

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 ...
user555045's user avatar
  • 12.6k
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, ...
Chris's user avatar
  • 5,482
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 ...
TorbenPutkonen's user avatar
4 votes

Shortest Cell Path In a given grid

Style Let's look at this conditional in shortestCellPathHelper. ...
Chris's user avatar
  • 5,482
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. ...
user555045's user avatar
  • 12.6k
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 ...
Chris's user avatar
  • 5,482
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 ...
J_H's user avatar
  • 43k
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 ...
Chris's user avatar
  • 5,482
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: ...
toolic's user avatar
  • 16.2k
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 ...
gdoura mohamed's user avatar
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 ...
toolic's user avatar
  • 16.2k
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 ...
Joop Eggen's user avatar
  • 4,696
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 ...
Chris's user avatar
  • 5,482
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 ...
greybeard's user avatar
  • 7,779
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'...
greybeard's user avatar
  • 7,779
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, ...
Chris's user avatar
  • 5,482
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 ...
Chris's user avatar
  • 5,482
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. ...
Chris's user avatar
  • 5,482
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 ...
Joop Eggen's user avatar
  • 4,696

Top 50 recent answers are included