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
1
vote
0answers
20 views

Reduce memory usage/lag with multiple large JSON files coming in through XHR

I need to show a map of the United States using Leaflet, where if the user clicks on a state, the map zooms in to view all of the state's census tracts. I need to do this without a significant delay ...
2
votes
1answer
69 views

Permutation code in C

I am pretty new to competitive programming. It took me almost 3 hours to make this, initially I started with 4 for loops and then to make it scalable for sizes bigger than 4, I decided to turn this ...
3
votes
0answers
46 views

Batch normalization code optimization?

I am trying to implement Deep Quaternion Networks. I was able to implement the batch normalization technique. But it requires a lot of GPU memory. Is there any way I can optimize the code provided ...
8
votes
2answers
492 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 <...
2
votes
1answer
54 views

Further Optimizing a Segmented Sieve of Eratosthenes

I've implemented a Segmented Sieve of Eratosthenes that assumes each segment is about length \$ \sqrt{N}\$ for some upper limit \$N\$. I further optimized the function by skipping all the evens when ...
-1
votes
2answers
156 views

TrainSet Practice Problem from CodeChef

A dataset consisting of N items. Each item is a pair of a word and a boolean denoting whether the given word is a spam word or not. There shouldn't be a word included in the training set that's ...
1
vote
2answers
60 views

Decrypt multiple 10Mb files with defined password

One operation of my Android project is to decrypt one file (chosen in a set of ~30 files for pagination1) of ~10 Mb each and I do this with the following: ...
2
votes
1answer
46 views

Optimizing a TFxIDF vectorization - Python 3.x [closed]

I am attempting to train many classifiers to test their performance with classifying tweets as being from a political bot, or not (a binary 0 or 1 classifier). My ...
4
votes
1answer
120 views

C# handling of images - is this best for memory usage?

I am working with a system that needs to consume product images uploaded by employees and resize them / add white padding to the sides to create square images to be consumed by our e-commerce site. I'...
2
votes
0answers
115 views

Split a string into valid words

I am trying to solve this LeetCode question: Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word ...
5
votes
1answer
74 views

Bank account balance program

Would my code be considered fairly optimal and efficient? If not, where can I look to improve the code? The program works just fine. Would this method scale well if the dictionary containing the ...
4
votes
1answer
105 views

Incremental Sieve of Eratosthenes Generator

So I was fiddling around with the Euler challenges. One of the things they mentioned in their discussions of the solutions is the Sieve of Eratosthenes and that you can only use it when you know an ...
4
votes
1answer
52 views

Optimizing away log function calls depending on global log level

I am a member of a university team designing a nanosatellite. We decided to implement our own (more lite) logging library to use, instead of, say, Google's glog, <...
2
votes
2answers
90 views

Generate a large block diagonal covariance matrix with exponential decay

I am implementing Kalman filtering in R. Part of the problem involves generating a really huge error covariance block-diagonal matrix (dim: 18000 rows x 18000 columns = 324,000,000 entries). We denote ...
1
vote
1answer
263 views

Clustering using k-medoids

This is the program function code for clustering using k-medoids ...
8
votes
1answer
199 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 ...
2
votes
2answers
94 views

Generating recursive class instances from an array of splitted values by dashes (as a folder tree)

Well, I'm trying to generate the following: Input: ...
6
votes
2answers
103 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 ...
2
votes
1answer
826 views

Python script for sorting a huge log file based on timestamps

I want to write a python script to sort a huge file, say 2 GB in size, which contains logs in the following format - ...
1
vote
1answer
64 views

Python's eval command in Arduino

I have made an equivalent of Python's "eval" command in Arduino (which in itself is quite a feat) but the part that decodes the output of it is not small enough to fit in another 30 functions since ...
3
votes
1answer
2k views

ASP.NET Core Request / Response logging middleware

I am looking for feedbacks about my ASP.NET Core Request / Response logging middleware, in particular in ways to lower the memory footprint and string allocations: ...
2
votes
0answers
42 views

Initializing Reinforcement Learning Q-Table State Space-Python

The code below is a "World" class method that initializes a Q-Table for use in the SARSA and Q-Learning algorithms. Without going into too much detail, the world has "Pickups" and "Dropoffs" that can ...
6
votes
1answer
138 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 ...
3
votes
3answers
138 views

Computing average duration per user from a large CSV file that doesn't fit in memory

We have a large log file which stores user interactions with an application. The entries in the log file follow the following schema: {userId, timestamp, actionType} where actionType is one of two ...
3
votes
0answers
304 views

Kadane's algorithms to leetcode “121 Best Time to Buy and Sell Stock”

I employed the conventional Kadane's algorithms to solve a maximum subarray problem in leetcode Best Time to Buy and Sell Stock - LeetCode Description Best Time to Buy and Sell Stock ...
4
votes
0answers
52 views

Two solutions to leetcode 127.wordLadder

I am working on Word Ladder - LeetCode Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such ...
6
votes
2answers
2k 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
1answer
111 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 ...
2
votes
1answer
80 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
383 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
469 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 ...
1
vote
0answers
128 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
205 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
54 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
81 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
60 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
67 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
577 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
109 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
127 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 ...
7
votes
2answers
129 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
76 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 ...
18
votes
2answers
5k 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 ...
9
votes
1answer
67 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 ...
1
vote
1answer
83 views

Trie structure using Hash in Ruby

This is a follow-up to Boggle board solver in Ruby ...
3
votes
1answer
171 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
24k 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
122 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
61 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. ...