Stack Exchange Network

Stack Exchange network consists of 174 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

0
votes
0answers
28 views

TCP Socket High CPU/Memory usage after 5mins

I'm building a server app that accepts incoming TCP connections. (roughly 300 unique clients). It's important to note that I do not have control over the clients. I have found that some of the ...
2
votes
1answer
59 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
44 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
53 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
378 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 ...
-1
votes
0answers
28 views

Basic image median filter

Recently I implemented the most basic moving window transform version of a median filter that I could (it was actually just to have a comparison for another method, so I wasn't trying to optimise it ...
2
votes
2answers
78 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
14 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
114 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
73 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
36 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 ...
14
votes
2answers
700 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
48 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
38 views

Trie structure using Hash in Ruby

This is a follow-up to Boggle board solver in Ruby ...
3
votes
1answer
118 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,...
2
votes
1answer
3k 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
113 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
72 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
165 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
107 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
104 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
775 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
76 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
96 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
86 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
75 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
279 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
331 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
376 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
93 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....
0
votes
0answers
53 views

Load URLs from a CSV file and scrape HTML for images to download

This code uses a lot of memory (I think it's crappy code, since it gives the error of out of heap memory) What are your recommendations? This code grabs a html ...
5
votes
1answer
85 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
129 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
376 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
118 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
37 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
104 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
185 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
552 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
142 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
143 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
319 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
276 views

Partial file encryption with AES

Task is to encrypt part of the file using aes encryption algorithm. I did ...
3
votes
4answers
395 views

Finding anagrams in Java (space-optimised)

I've lately been asked in a job interview to program a solution for the well known anagrams problem: given two strings s1 and s2,...
5
votes
1answer
522 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 I had to ...
7
votes
2answers
890 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 ...