24 votes
Accepted

Intersection over Union for rotated rectangles

1. Review The large bounty suggests that getting a review of this code is important. But there are some other things you could have done to make reviewing this code more productive: Give us some ...
Gareth Rees's user avatar
  • 49.6k
20 votes

Printing 300 pages

I try to manually dispose as much as I can This is usually good however this time you dispose too much. ...
t3chb0t's user avatar
  • 44.3k
14 votes
Accepted

Printing 300 pages

don't mix german and english words for names. Best is to stick to english because most/all developers knows the language. don't repeat yourself. You have some duplicated code which should be removed. ...
Heslacher's user avatar
  • 50.4k
14 votes

Read CSV and use bidirectional BFS to find the shortest connections between actors

It looks like you found a pretty nice approach there already. A few general things stand out: Using globals Magical constants and unsafe C-style arrays/raw pointers: ...
sehe's user avatar
  • 1,322
12 votes

Binary file validity in C++/C++11: checking a binary header

The most unforgivable fault with this function is that calling isValidBuffer() also erases the buffer! That completely violates the Principle of Least Surprise. If ...
200_success's user avatar
12 votes

Number guess game program in python 3

Your comments describe what the code is doing, not why the code's doing what it is. And so are generally unhelpful. Please don't use profanity in comments, or anywhere. It makes you look ...
Peilonrayz's user avatar
  • 43.3k
11 votes

Printing 300 pages

Do not manually call Dispose(), you will end-up having some duplication (and you're not even disposing those resources in case of errors...). Use ...
Adriano Repetti's user avatar
10 votes

Rust Brainfuck interpreter

Profile You can only improve what you can measure. So first of all let us run callgrind to check where we spent most of our time: ...
Zeta's user avatar
  • 19.3k
10 votes
Accepted

Calculating the Average Minimum Length of Random Numbers From 0 - 1 that Adds up to Greater Than 1

If I rewrite genSequence so that it takes numTrials as an argument, then I get the following timing in CPython: ...
Gareth Rees's user avatar
  • 49.6k
9 votes

Improving gzip function for huge files

inF = gzip.open(FILE, 'rb') s = inF.read() inF.close() That reads the whole uncompressed data into memory. Of course it takes 60GB of memory. Looking ...
Peter Taylor's user avatar
  • 24.1k
9 votes

Intersection over Union for rotated rectangles

There are two main reasons why your program is slow and using huge amounts of memory: You are using a 768×768 pixel image for each overlap calculation You are checking each anchor box against each ...
G. Sliepen's user avatar
  • 55.4k
9 votes

Implementation of itoa which allocates the string

Counting the digits doubles the amount of work, and the division/modulo is indeed very hard work for the CPU. You know the maximum size of the resulting string, because it would be the largest or most ...
JDługosz's user avatar
  • 11.3k
9 votes
Accepted

Simple stack allocator in C

Bug: Invalid address computation StackPointer + length > Stack + sizeof(Stack) for this to be true, StackPointer + length ...
chux - Reinstate Monica's user avatar
8 votes
Accepted

Choose random instants in a day with a low memory footprint

1. Review There's a lot of repetition, especially of the number 86400. This can be avoided by defining a global constant, for example: ...
Gareth Rees's user avatar
  • 49.6k
8 votes
Accepted

In place solution to remove duplicates from a sorted list

One way that might speed up your solution slightly is to only place the value if necessary. Also note that only one of the two if conditions can be true, so just ...
Graipher's user avatar
  • 40.9k
7 votes
Accepted

Rotation of elements in an array

I see some things that may help you improve your program. Separate I/O from calculations The program has three basic phases. First, it gets input, then it manipulates that input, and then it ...
Edward's user avatar
  • 66.4k
7 votes

C++11 : simple Tree implementation

Encapsulation: My first question is why are you exposing TreeNode? Would the class that implemented a tree not be represented by ...
Martin York's user avatar
7 votes

Split a given number so that their sum adds to another given number

Python 2 Python 2 is end-of-life, and Python 3 has a lot of advantages now: f-strings unicode support ... More info here, here and on many other places. If you need python 2.7, try to make your ...
Maarten Fabré's user avatar
7 votes

Search father (x) of the number D(x) and measure time and memory consumed

PEP-8 Try to stick to PEP-8. So snake_case for variable and method names and a lot of other guidelines. Check any other Code ...
Maarten Fabré's user avatar
7 votes

Sparse 3D binning/histogram function

Some suggestions: Passing the code through at least one linter such as flake8 or pycodestyle will make for more idiomatic and therefore readable code. Do you have any automated tests? If so, do they ...
l0b0's user avatar
  • 8,917
7 votes
Accepted

Computing average duration per user from a large CSV file that doesn't fit in memory

This is a comment on your Python solution (I don't know anything about Scala). You don't need to iterate over chunks of your file unless you want to do parallel processing. However, since there might ...
Graipher's user avatar
  • 40.9k
7 votes

Implementation of itoa which allocates the string

Besides lots of optimizations other people have suggested, you have two memory leaks. The first is that, just before the final return in itoa(), you need to write ...
David G.'s user avatar
  • 1,333
7 votes
Accepted

Find all possible ways a rook can move to a diagonally opposite corner without going back to an already visited square

I would recommend that you change struct Square to record Square. This makes all the comparative stuff much easier. Then you can ...
jdt's user avatar
  • 2,362
7 votes
Accepted

Memory leak I can't identify using Bitmap and Graphics classes

Just few tips Prefer using over manual calling Dispose(). Consumed memory isn't always busy memory, GC can free the memory ...
aepot's user avatar
  • 2,009
7 votes

Find median value of two Sorted Arrays

context You likely obtained the problem statement from leetcode or similar. It would be helpful to share its text and the URL. PEP-8 ...
J_H's user avatar
  • 24.7k
6 votes
Accepted

Computing the double Integral using MonteCarlo techniques using Julia

Try swapping out the three arrays with calling a function iteratively---three Int64 arrays (each element 8 bytes) of ~100M elements is a lot. That is, switch out the body of the ...
nybblet's user avatar
  • 76
6 votes
Accepted

Memoized Collatz sequence

It doesn't use 300 megabytes of heap, it peaks at a little over 20 megabytes. Total allocation is not peak allocation and Haskell has cheap short-lived allocations so total alloc isn't always a good ...
bitemyapp's user avatar
  • 329
6 votes
Accepted

Find files with content matching regex

Your try block for importing reduce is unnecessary. In Python 2, it is still in the ...
zondo's user avatar
  • 3,787
6 votes
Accepted

Genetic Sequence Visualizer - Generating large images

Parser Your parser has a bug in line 62: raw = ''.join([n for n in file.readlines() if not n.startswith('>')]).replace('\n', "").lower() will ...
FirefoxMetzger's user avatar
6 votes
Accepted

Simple recursive transformation solution in Python

Your code works correctly – as far as I can see – for strictly positive integers \$ a, b, c, d \$. It fails if the integers are allowed to be zero or negative. For example: ...
Martin R's user avatar
  • 23.2k

Only top scored, non community-wiki answers of a minimum length are eligible