memory-efficient

Capturing Non-Zero Elements, Counts and Indexes of Sparse Matrix

I have the following sparse matrix A. 2 3 0 0 0 3 0 4 0 6 0 -1 -3 2 0 0 0 1 0 0 0 4 2 0 1 Then I would like to capture the following information from there: cumulative count of entries, as matrix is scanned columnwise. Yielding: Ap = [ 0, 2, 5, 9, 10, 12 ]; row indices of entries...

Memory-efficient way of computing the median of a large data set?

If one computer can only hold 1 million numbers, how to find out the median number from 100 million numbers? ...

What's the most efficient way to load data from a file to a collection on-demand?

I'm working on a java project that will allows users to parse multiple files with potentially thousands of lines. The information parsed will be stored in different objects, which then will be added to a collection. Since the GUI won't require to load ALL these objects at once and keep them in memory, I'm looking for an efficient way t...

tidy/efficient function writing in R

Excuse my ignorance, as I'm not a computer engineer but with roots in biology. I have become a great fan of pre-allocating objects (kudos to SO and R inferno by Patrick Burns) and would like to improve my coding habits. In lieu of this fact, I've been thinking about writing more efficient functions and have the following question. Is th...

Memory Efficient file append

i have several files whose content need to be merged into a single file. i have the following code that does this ... but it seems rather inefficient in terms of memory usage ... would you suggest a better way to do it ? the Util.MoveFile function simply accounts for moving files across volumes private void Compose(string[] files)...

what's more efficient? checking == or just mutating the variable?

Imagine I had a variable called X. Let's say every 5 seconds I wanted to make X = true. (it could be either true or false in between these 5 seconds, but gets reset to true when the 5 seconds are up). Would it be more efficient to check if the value is already true, then if not, reassign it to true? Or just have X = true? in other word...

Building an EFFICIENT Sudoku Solver.

Hey everyone, Yes, I know this is nothing new and there are many questions already out there (it even has its own tag), but I'd like to create a Sudoku Solver in Java solely for the purpose of training myself to write code that is more efficient. Probably the easiest way to do this in a program is have a ton of for loops parse through ...

Efficient way to keep a graph (2-D array)

Hi Does anyone know a more efficient way to keep a graph information (i.e. more efficient than keeping it as 2-D array), in terms of memory space or build time? you can assume it's values are limited between 0-255. Thanx! ...

Memory-efficient string-to-string map in Python (or C)

I need a memory-efficient data structure for for storing about a million key--value pairs, where keys are strings of about 80 bytes, and values are strings of about 200 bytes, the total key and value size being about 280MB. I also need efficient lookup of value by key, preferably a hash-map. The memory overhead should be as little as pos...

An Efficient way of randomizing an array - Shuffle code

Hi, I was asked this question in an interview and I gave various solutions but the interviewer was not convinced. I am interested to find a solution. Please throw in your views : Q: Write an efficient data structure to implement the shuffle in an ipod. It must play all the songs, each time in different random order, the same song shou...