Questions tagged [memory-optimization]

Memory Optimization is a subset of Optimization: it is the goal of reducing the memory consumption (the amount of memory used during compile or run time) of your program or of a specific algorithm

Filter by
Sorted by
Tagged with
8
votes
3answers
159 views

How to decrease memory usage in codeeval Road Trip challenge

I'm solving easy CodeEval challenges in Python 2.7. Usually my solutions use around 256 bytes of memory according to CodeEval. With Road Trip however while time used is still low (30-40ms), memory is >...
2
votes
1answer
128 views

Profit sensitivity analysis in base R

Using base R, I've conducted a simple profit sensitivity analysis, i.e. measuring the impact on profit if there is a change in price, variable cost per sale, unit sales or fixed costs assuming that ...
3
votes
0answers
51 views

LinkedList of Nodes at each level - optimalization

That's already known problem: to return an array of linked lists that contain values of elements at each level. Eg for tree with depth n there should be n linked lists. I wrote the solution: ...
3
votes
1answer
122 views

Writing a byte array image to disk with an automatically generated filename

I have the following code that that writes large images to disk. My application server is running out of memory and I'm wondering if I could somehow optimize the following: ...
2
votes
2answers
74 views

Find the best path amongst N random points

For an application with a graphical canvas, I want to generate N points. But then I want to link those points, and I want to find the best path through those points. I wanted to use a dynamic ...
4
votes
1answer
174 views

Memory efficient Log Parser

I wrote this together for a test I'm doing that parses the Heroku access log. What I'm mainly interested is if this code follow common best practices and if there are any improvements I can make in ...
1
vote
1answer
3k views

Multiple emails and attachments, reusing memory stream

I am generating a pdf form based on user input from an MVC website form. The pdf is genrated using the Foxit .NET SDK, then attached to three separate emails, generated using Postal. It has been ...
4
votes
2answers
892 views

Memoized Collatz sequence

Here is one of my programs that utilized memoization and array to improve performance and memory usage. The performance seems satisfactory but the memory usage is ridiculous and I can't figure out ...
7
votes
3answers
9k views

Rotation of elements in an array

We had to write a program that would perform rotation of elements in an array. The array size was entered by user, so it had to be in a sense, dynamic. Rotation or Circular Shifting Initial Array: <...
4
votes
2answers
877 views

Memory Management Code

For a project I had to do a memory management problem without creating any custom classes or templates using the provided pool array and ...
4
votes
2answers
1k views

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

I have some code for checking a binary header to see if a binary file is meant to be read by a certain program, and I could use some extra eyes to review it. Assume the following ...
4
votes
1answer
309 views

Construct binary tree from inorder and postorder traversal

The problem is taken from here. The tree is guaranteed not to have duplicate elements. My questions is, instead of creating new arrays leftInOrder, ...
3
votes
2answers
725 views

Find two numbers that add up to a given total, from a formatted string

The full challenge from codeeval.com can be viewed here. Input Your program should accept as its first argument a filename. This file will contain a comma separated list of sorted numbers ...
4
votes
2answers
212 views

Computing the double Integral using MonteCarlo techniques using Julia

I decided to try and learn Julia for doing scientific computing, and I decided to tackle the problem of finding $$ \int_{D_{\frac{1}{4}}} x^4 + y^2 dA $$ where \$ D_{\frac{1}{4}} \$ is the part of ...
-1
votes
1answer
250 views

Simplest linked list in C++?

My context was basically to get my linked list implementation in C++ reviewed, since I wrote it from scratch and wanted to make it as simple as possible and learn from suggestions I get. I am trying ...
6
votes
2answers
276 views

Extending Sieve of Eratosthenes beyond a billion - follow-up

Follow up form Extending Sieve of Eratosthenes beyond a billion Taking suggestions from the comments on the previous post: Updated Code: This takes about 22 seconds for MAX as \$10^9\$ to reach "...
12
votes
1answer
307 views

Where it all begins: Khronos

This is the main.c file for Khronos, a personal project of mine. This is basically where the whole program is setup, run and then quit. I'll post the short ...
31
votes
4answers
3k views

Extending Sieve of Eratosthenes beyond a billion

For MAX value of 1000000000 (\$10^9\$), it takes about 45 seconds to reach the line where it prints "done". How can I speed this ...
20
votes
1answer
3k views

Bruteforce MD5 Password cracker

I just started learning Go, and I wanted to created a project to learn more about concurrency in go. I heard about Go's lightweight threads, so I wanted to give them a try. This program uses ...
9
votes
2answers
2k views

Frequency count of single words and word pairs over 20 million tweets

My application needs to read 20-million-line text files and count the word frequencies for one and two words. For example: A B A B SSS G D A One word Frequency A: 3 B: 2 SSS: 1 G: 1 Two Word ...
3
votes
1answer
210 views

Tic Tac Toe with Minimax (memory management optimization)

I've made a Tic Tac Toe game with minimax in Javascript. It works but I have to use location.reload(true); to automatically reload the page every time user starts a ...
7
votes
3answers
546 views

Type-agnostic BubbleSort in C

I'm trying out different sorting algorithms for learning purposes, here I'm doing a "type-agnostic" bubbleaort. I modeled the function signature after the standard library's ...
5
votes
1answer
1k views

Updating number of votes with a "Like" button

I have a "Like" button in my iOS app that updates the votes every time it's tapped. Just like Facebook, Instagram, ProductHunt, etc. I have a custom cell where that ...
4
votes
1answer
560 views

Conway's Game of Life

Inspired by this post, I decided to try to implement my own Conway's Game of Life. I started with a non-warping board: ...
2
votes
1answer
62 views

Compare a sequence with the reference frequency of hexamers

I have written this function (and others similar to that one) But I am not sure I am using references on their full power. My currently concerns is if I make a huge use of memory. The subroutine ...
4
votes
1answer
88 views

Binary/yijing clock in Processing with excessive resource consumption

I've been learning Processing for the last week or two, and I've made a couple of little 'desktop toy' type apps like this one that I'm quite pleased with. However, it just occurred to me today to ...
2
votes
0answers
569 views

"Partial solution" on Code Eval for Clojure FizzBuzz

I'm just getting started on the site CodeEval, and I submitted my first solution today. What I don't understand is why it's marking my (working) answer as only a "partial solution". The site doesn't ...
2
votes
1answer
1k views

Extract data from large JSON and find frequency of contiguous sub lists

I have been writing some code (see component parts here and here) that: Takes a very large JSON (15GB gzipped, ~10million records) Extracts the relevant parts of the JSON into a list of lists Creates ...
4
votes
1answer
2k views

Pulling data from API, Allowed memory exhausted

I'm working on a project where I pull data (JSON) from an API. I would like to manipulate this data and store this as useful information in my DB (MySQL). My code is working if I would like to make, ...
10
votes
2answers
1k views

Unique value finder

For our first assignment in our algorithm class we are suppose to solve several different questions using information from a 2D array. We are also suppose to optimize our code to get more marks on our ...
3
votes
3answers
180 views

Storing and processing large arrays to compute dot products

Problem Statement (from HackerRank) We have two arrays \$a\$ and \$b\$ of length \$N\$, initially all values equals to zero. We have \$Q\$ operations. Let's define three types of operations on ...
7
votes
1answer
710 views

Monitoring the recursive growth of a zombie rabbit population

Breeding like rabbits Write a function answer(str_S) which, given the base-10 string representation of an integer \$S\$, returns the largest n such that \$R(...
6
votes
1answer
329 views

Sieve of Eratosthenes for prime generation

I was originally going to write this intro as just being the bare-bones "here's my problem, here are some ideas, what do you recommend" format (which I am still going to follow, mind you), but I've ...
8
votes
2answers
272 views

Summation of primes for large inputs

I'm doing a problem from Project Euler to find the sum of all primes under two million. My code manages to get a pretty good result for small inputs, but when trying inputs like million or two it ...
5
votes
1answer
436 views

CodeEval solutions to find trailing strings

This is a problem in CodeEval, moderate level. The problem is very easy for this level. But I am not able to get more than 60 points for any solution I submit. (Moderate levels highest score is 65 and ...
3
votes
3answers
3k views

Custom ArrayList class

Please review my custom ArrayList class I constructed from scratch and add any suggestions or constructive criticisms. The point of this template class is give the ...
4
votes
2answers
1k views

Memory efficient A* (AStar) Algorithm

I am writing a solved for 15 puzzle game which will find the solution path to any NxN board. For easier boards the algorithm works great solving almost any 3x3 boards, most 4x4 boards, but when I go ...
4
votes
2answers
1k views

Object-oriented JavaScript and Google Maps objects memory management

I have to draw various instances of HeatMaps, Winds and Polylines. Each layer will have one <...
3
votes
3answers
1k views

Web crawler uses lots of memory

I am developing a web crawler application. When I run the program for more than 3 hours, the program runs out of memory. I should run the program for more that 2-3 days non-stop to get the results I ...
6
votes
1answer
211 views

Pool allocator for a scripting language parser

At the moment I'm writing a parser and interpreter for a custom scripting language, to learn more about the basic concepts involved and to get more familiar with tools like ...
32
votes
1answer
1k views

Rust Brainfuck interpreter

I took the code from kostyas benchmarks for the Rust Brainfuck interpreter and tried to optimize it. There is also a discussion on Reddit about the poor performance of Rust in the Benchmark. Before ...
3
votes
1answer
71 views

Yellow Pages Search

I've written code in Free Pascal based on a contest problem (The contest insists that I have to write with Pascal). It works like charm, but I think it still need some improvements, from memory usage ...
4
votes
5answers
2k views

Permutation of n lists

I have code which gives permutations for 10 lists. The code works fine for small number of lists with small number of values. Result : It should return all possible permutations. I have to store the ...
3
votes
2answers
233 views

Effecient Use Sieve of Eratosthenes algorithm

Given this as a the Problem Statement Given two numbers, find the sum of prime numbers between them, both inclusive. Input: The first line contains the number of test cases T. Each ...
6
votes
2answers
1k views

Two-dimensional array, modified one field at a time

Title says it all. I'm basically initializing a two-dimensional array and changing the fields one at a time. It might be a good idea to do this OO. A Grid class ...
4
votes
2answers
138 views

Reducing memory usage for FizzBuzz in R

I've been trying all night to get my fizzbuzz to use below 20 MB of RAM but I can't seem to get it much smaller than this. ...
3
votes
1answer
905 views

Number of paths in a grid (lattice) graph

I am trying to solve a variant of the very popular question in which we find the number of distinct valid paths on a directed graph. The graph's nodes make up a m x n lattice (grid), and the edges ...
6
votes
3answers
164 views

SPOJ Adding Reversed Numbers

Recently, I was taking up this challenge and choose my favorite language 'Ruby' to do it. My following solution got accepted (Gist). For each test case, I am to reverse two numbers, add them, and ...
3
votes
1answer
114 views

Haskell requires more memory than Python when I read map from file. Why?

I have this simple code in Python: ...
2
votes
1answer
106 views

Candy splitting - lower memory usage needed

I just did CodeChief's candy splitting task here and my code is working even with a lot of test cases and big numbers, but it uses way too much memory. When I checked my submission, it was 1342M, ...