Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

2
votes
1answer
70 views

Writing a more Pythonic solution to the min triangle path

The problem I'm referring to is available here. In quick summary, the problem gives a list of lists such as [[2],[3,4],[6,5,7],[4,1,8,3]] and we must find the minimum path sum: 2 + 3 + 5 + 1 = 11. I ...
15
votes
3answers
305 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,...
3
votes
1answer
51 views

json2CSV fails because of lack of RAM memory

I run this code on my Heroku Node.js server in order to get CSV for few hundred rows, but it fails with R14 - Memory Quota Exceeded. It worked fine when there were ...
0
votes
0answers
49 views

Golang message bus for a game engine

I wrote a memory bus struct in golang to allow systems to interact with each other without knowing anything about the receiver. This is for a game engine. I know it's not good to write games in ...
1
vote
4answers
127 views

Read a palindrome of unknown length

I have a task to write the function: int read_palindrome(); // input comes from stdin which will read one line from standard input and returns 1 if the line is a ...
1
vote
2answers
53 views

Check whether an array can be the result of merging two smaller arrays, maintaining order

I'm prepping for a tech interview coming up and trying to have a better understanding of what I should look out for in writing code. Also, feel free to correct the terminology that I use as I want to ...
2
votes
1answer
77 views

Grouping items in a list into inner lists

I have a function that looks up in a list the elements which share same values in order to group them. As a fast summary, this should be the input/output: [A, A'...
3
votes
0answers
50 views

Minimization problem solving and its step limits

I am trying to solve the following minimization problem: $$ \min\lvert\lvert{x}\rvert\rvert_1 + \beta\lvert\lvert{x}\rvert\rvert^2_2 s.t. \sum_{m = 1}^M (y - \lvert{c}^{H} . x\rvert^2)^2 \le \epsilon ...
1
vote
1answer
59 views

Header-only vector implementation in C

I tried to make a generic, header-only vector thingy I can use in other projects in the future. I omitted documentation comments because it's already quite long. ...
8
votes
2answers
414 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 ...
2
votes
2answers
87 views

Genetic Algorithm - heavy memory usage

I have implemented two pieces of code as part of an Evolutionary Algorithm study: Particle Swarm Optimisation (PSO) and Genetic Algorithm (GA). Both are designed to find an optimal solution to a ...
1
vote
0answers
15 views

Swapping variable length strings asynchronously with connected microcontroller (Byte-banging)

I have an AT89S52 and an AT89C4051 microcontroller (both in the 8052 family) in which the bit lines of the data bus, one control pin and one status pin are connected together. In code, the data bus is ...
3
votes
2answers
120 views

Simple recursive transformation solution in Python

This simple Python code I wrote for a problem asked during an interview. The problem statement is: Given a tuple (a, b), transform this into (c, d) by applying any of the two below operations ...
6
votes
2answers
90 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 ...
1
vote
0answers
37 views

Applying a filter to a large array with elements that are not regularly spaced

I need to apply a Gaussian filter to a 2D numpy array where the distance between adjacent array elements depends on the row of the array. (Specifically, the data are evenly spaced in latitude and ...
15
votes
2answers
1k 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 ...
6
votes
1answer
49 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 ...
0
votes
1answer
39 views

Trie structure using Hash in Ruby

This is a follow-up to Boggle board solver in Ruby ...
3
votes
1answer
126 views

Optimizations of C Code - Bilateral Filter

I'm working on a nice approximation for the Bilateral Filter. I have a working code which runs pretty fast yet still I think much can be improved. The code (C Code,...
5
votes
1answer
6k 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 ...
2
votes
1answer
115 views

Find the nearest coin to be collected in a game

I am creating a simple bot that collects coins in-game. The code runs under a game-loop so there are 60 ticks p/s Here is the function that I use to check for the nearest coin (Game object) to be ...
2
votes
2answers
59 views

Eigenvector calculation involving three matrices

Code performs well for small matrices, but gives memory error for large matrices of size 63000x93000, even when I am using server with memory of 64GB, space 100GB, swap 40GB. ...
1
vote
2answers
90 views

Codility's BinaryGap: Hardware-aware answer [closed]

This is a well-known question, which some others have posted about on this site. Here's my first shot following a state machine approach: ...
4
votes
1answer
195 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 ...
8
votes
2answers
110 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. ...
3
votes
0answers
124 views

Pandas data extraction task taking too much memory. How to optimize for memory usage?

I need to process some data (one of its columns contains a json/dict with params- I need to extract those params to individual columns of their own; catch- some rows have some parameters, others have ...
4
votes
1answer
1k views

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

Task You are given a string S containing only decimal digits ('0' through '9') and a number N. Your task is to insert an arbitrary number (including zero) of plus signs '+' into S in order to ...
6
votes
1answer
77 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: ...
3
votes
2answers
97 views

Littlewood Polynomial Heatmap

The following Python program generates heat maps of the roots of Littlewood polynomials. It works fine with a small number of roots, however I tried to use 2^21 in the first loop and it ate up 12 ...
6
votes
2answers
94 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 ...
11
votes
1answer
92 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 ...
5
votes
2answers
82 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 ...
1
vote
1answer
2k views

Generating a word bigram co-occurrence matrix

I have written a method which is designed to calculate the word co-occurrence matrix in a corpus, such that element(i,j) is the number of times that word i follows word j in the corpus. Here is my ...
8
votes
1answer
281 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) ...
4
votes
5answers
467 views

Find The Duplicates in two arrays

Find The Duplicates Given two sorted arrays arr1 and arr2 of passport numbers, implement a function findDuplicates that returns an array of all passport numbers that are both in arr1 and arr2. Note ...
6
votes
1answer
447 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 ...
5
votes
1answer
95 views

Rich Edit Form Input (x86-16)

This procedure is the natural continuation of the Example 4 that I wrote for How buffered input works, a Stack Overflow Q/A. Features include: freely positioning the cursor. Left Moves cursor left....
5
votes
1answer
89 views

C++ class to compute similarity coefficients

I'm a complete beginner in C++. I wrote a class to compute similarity coefficients using Euclidean distance and Pearson coefficients on map data structure. I would ...
4
votes
0answers
134 views

A Java neural network

I have created a neural network in Java, it contains multiple classes. I have uploaded the documentation for the network here: Doxygen, and the full source can be found on Github. Let me start out by ...
6
votes
2answers
436 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 - #...
1
vote
1answer
121 views

Implement C++11 multipart sending without copying to a single buffer

I am working on a C++11 project and am migrating the underlying communications library used. The original library allowed sending messages in multiple parts using a ...
1
vote
0answers
44 views

RFID card reader validation routine in 8051 assembly

I came up with the following code to check to see if the last 2 bytes of a 12-byte value read in from a RDM6300 card reader is actually the checksum of the first 10 bytes. ...
1
vote
2answers
113 views

Heap space issue with queue

I need some help with this code which is giving me a heap space issue. I have tried executors too but still I get out of memory issue. The consists of a queue which initially holds an endpoint. The ...
3
votes
1answer
198 views

Counting subsets with sum not exceeding some limit

I am facing a variation of a subset sum problem. I have to count the number of subsets with sum less than or equal to some integer(limit). I think the optimal solution for this problem would be the ...
5
votes
2answers
589 views

Permutation of objects, increase maximum limit

I am using this function to find all permutation of objects of a given length. However, right now, the maximum length I can reach before it throws an "Out of memory exception" is 9 (also, it gets too ...
4
votes
2answers
148 views

Using a radix tree to find case-insensitive matches in large files

I'm using a radix tree library to find case-insensitive matches from several relatively large files (~24 files each on the order ~150MB). My current algorithm requires me to read the chars of an ...
3
votes
0answers
158 views

Cleaning up memory after loading Access DB into a datagrid

I wrote an app that pulls a MS Access DB into a DataTable and then displays it into a WPF datagrid. The dialog window has a search button which calls on a class ...
4
votes
3answers
122 views

Associating a string with a derived class

I am using the following code to get a string that is associated with the class of an instance: ...
3
votes
0answers
345 views

Populate MongoDB with random documents using a Go channel

I recently created a small app in Go that generates random bson documents and insert them in a database (MongoDB). See this question for details. After doing some profiling, I realised that garbage ...
2
votes
0answers
318 views

Partial file encryption with AES

Task is to encrypt part of the file using aes encryption algorithm. I did ...