We changed our privacy policy. Read more.

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
35
votes
5answers
7k views

Recording Audio Continuously in C

As an ongoing little side project of mine, I've been working on recording audio in c. You can the code's progression by looking at past versions (V1.0, V2.0). I've found that my past versions were ...
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 ...
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 ...
18
votes
2answers
9k views

Intersection over Union for rotated rectangles

Problem Statement I am trying to find the intersection over union (IoU) metric for one to several rotated rectangles compared to many different rotated rectangles. Here are some images to help ...
16
votes
3answers
532 views

Traversing an infinite graph using Dijkstra's algorithm to maximize cookie production speed

Imagine the following situation: It is the year 20XX. You are a prodigious baker, capable of baking cookies at an astonishing rate of 1 cookie per second. Your archnemesis, an equally excellent baker,...
12
votes
4answers
3k views

Printing 300 pages

I have a problem with my printing program, in which it uses up too much resources while printing (to paper or to .pdf). I try to manually dispose as much as I can, but for example, when I tried ...
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 ...
11
votes
1answer
109 views

Python genetic sequence visualizer

I'm a beginner at python, and this is my first major project. Inspired by this reddit post, I wrote a program that accepts a DNA sequence (in a FASTA file format) and generates a graphical ...
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 ...
10
votes
3answers
1k views

Compression Library for C using Huffman Coding

This is an update to a question I posed nearly two years ago about my implementation of Huffman Coding which I had written in C. Since then I have had time to grow as a programmer and have managed to ...
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 ...
9
votes
1answer
77 views

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

We define function D(x) as following: D(x) = x + sum of digits of x + sum of prime factors of x then call x the father of D(x) Write a program that gets input ...
9
votes
1answer
411 views

Custom malloc implementation

I have a malloc() implementation that relies purely on mmap. I'm fairly sure that it doesn't overwrite any of the internal ...
8
votes
2answers
836 views

Sparse 3D binning/histogram function

This is a function written in Python I wrote to process galaxy catalogs for cosmology research, however it is more generally applicable than just my pipeline. The goal is to take a Python list of ...
8
votes
1answer
295 views

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

My Computer Science teacher gave us a task to calculate the average after one billion trials. His exact assignment was this: Consider generating a sequence of random numbers on the interval [0, 1) ...
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 ...
8
votes
2answers
747 views

hexdump(): A memory layout utility to help debugging / understanding / optimising of C++ memory model

EDIT: Refer this answer for improved solution with incorporated feedback and extended functionality. eg Automatically hexdump both parts of a stack/heap obj like <...
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 >...
8
votes
2answers
272 views

Maximize a traveling employee's vacation over k weeks

I have following problem statement A lazy employee works at a multi-national corporation with N offices spread across the globe. They want to work as few days over k weeks as possible. Their company ...
8
votes
1answer
3k views

Make To and From date range picker using jQuery UI

I implemented date range picker logic using the jQUery UI datepicker component: ...
7
votes
2answers
1k views

Number guess game program in python 3

I started learning Python just yesterday, and so I am aware of my lack of knowledge regarding the language. Below is a program I wrote to simulate a guessing game. I ended up creating a lot of ad hoc ...
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: <...
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 ...
7
votes
2answers
772 views

The performance of the simulation for an ant's random walk on a 5x5 grid

I have written a simulation in order to solve the 280th problem in Project Euler, and the simulation basically repeat the given experiment 5m times, and for each experiment, writes the ExpNo - #...
7
votes
1answer
712 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(...
7
votes
2answers
150 views

Prime number segmented sieve

I tried to solve the SPOJ prime number problem below. The code produced correct results, but Time limit exceeded and also memory need around 970M which is not efficient(?) How can I optimize this ...
7
votes
1answer
38k views

Count duplicates in a JavaScript array

This is actually a hackerrank interview question I have already solved but I need guidance on how to optimize it for the Time Space Given an array of integers, your task is to count the number of ...
7
votes
1answer
1k views

Huffman Coding library implemented in C

I have written a small library for C that implements the Huffman coding algorithm as outlined in David Huffman's paper on Minimum-Redundancy Codes, and a small test program to implement it. The ...
7
votes
1answer
954 views

Optimizing variable order Markov Chain Implementation

I've created a variable order Markov chain built on top of a tree, but I can't train on datasets >1MB worth of text without running out of memory. I'm sure the tree can be replaced by something else ...
6
votes
1answer
631 views

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

I have a really huge file¹ with 17 million records in it. Here is a sample of the file: Actor Movie 1,2 2,2 3,1 4,3 2,3 ...
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 "...
6
votes
3answers
4k views

In place solution to remove duplicates from a sorted list

I am working on the problem removeDuplicatesFromSortedList Given a sorted array nums, remove the duplicates in-place such that each element appear only once and ...
6
votes
2answers
166 views

Genetic Sequence Visualizer - Generating large images

Inspired by this reddit post, I have written a program that accepts a DNA sequence (in a FASTA file format) and generates a graphical representation. HIV virus and Ebola virus My program works like ...
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 ...
6
votes
2answers
106 views

Program for activity selection exceeds time limit

I've been trying to solve this problem for some while and the solution I have come up with exceeds the lime limit by 1-3 ms and 2 out of 10 tests get a memory issue error. Why is that? This is the ...
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 ...
6
votes
1answer
161 views

Matrix class with space-optimized triangular (lower and upper) variants

I've written a class for square numerical matrices (of doubles, in this case), in C++11. Since I intend to use this class later ...
6
votes
1answer
93 views

Python script which sends telegram message if Raspberry Pi's temperature crosses 60 °C

I need to know if there is any way I can optimize my code so that it does not use 0.6% of my total memory - which is approx. 22.4MB. This is a really small script that runs for as long as the ...
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 ...
6
votes
1answer
83 views

Build embedded XML based on string containment

I have a list of strings that represent a path. These are unique, unsorted values that look like this: ...
6
votes
1answer
212 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 ...
6
votes
1answer
198 views

Ternary Search Tree / N-Gram Model in Python

I implemented a word n-gram model using a character ternary search tree. It is intended to be passed a generator that yields a long sequence of words (from a corpus) and its requirements are that it ...
6
votes
0answers
469 views

Kattis problem Amanda Lounges

I wrote this solution to Kattis problem Amanda Lounges in Scala. TL;DR: It's a graph theory problem where I read in a list of edges from stdin and try to compute the minimum number of nodes that ...
5
votes
6answers
1k views

Implementation of itoa which allocates the string

This is my implementation of itoa() (Integer to Alpha), which converts an integer to a string. Memory management and optimization is important. The caller is not ...
5
votes
1answer
528 views

Choose random instants in a day with a low memory footprint

I'm looking for a way to plan a list of X events at the start of the day... What I did before: At 02:00 every day, choose X timestamps from "now" to 01:59 the next day. That worked well but ...
5
votes
1answer
2k views

C++11 : simple Tree implementation

I have created a C++11 implementation of a simple Tree for an online code challenge, I'd like to know how to improve it and how to make my code use less memory : ...
5
votes
2answers
96 views

Transpose tab-delimited table in C

I have looked online for transposing programs, but have found that they have extreme RAM use for large tables. The RAM use is so extreme I can't run most jobs on my laptop. I also have a Perl ...
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 ...
5
votes
1answer
67 views

Improving efficiency of download code

I'm in the process of reviewing some old code released by an old colleague. We have a cronjob that executes once in an hour to download some thumbnails: the paths to the thumbnails are stored in a ...

1
2 3 4 5