Optimization is the act of improving a method or design. In programming, optimization usually takes the form of improving the efficiency of an algorithm, or reducing the resources it requires (space in memory, on disk, or amount of network traffic, etc.).

learn more… | top users | synonyms (2)

1
vote
0answers
5 views

Find the combinations, given three datacenters with x number of machines

I am working on a project in which I have three datacenter (as of now) and each datacenter will have some machines. So I am storing the input in a Map of String and List of String as shown below. ...
6
votes
1answer
42 views

Highlight countries based on category

In the below code I should highlight countries on the map based on the category of the country in which there are 2 different type of countries (issuing office and selected countries). Based on the ...
2
votes
1answer
39 views

How to generate balls and box combinations depending on rule set I have?

I am working on a project in which I have three box (as of now) and each box will have some color of balls So I am storing the input in a Map of String and List of String as shown below. ...
2
votes
1answer
57 views

Speedup cython dictionary counter

I wrote a simple cython script to optimize the collections.Counter of a dictionary counter and the python zip implementation (the main input is a list of tuples). Is there a way to speed it up? ...
1
vote
1answer
71 views

How to turn 201 queries into 1? [on hold]

I have a PHP web app that manages contacts. It has four main functions that display: contacts with upcoming birthdays; the 20 most viewed contacts; all contacts (200 limit) plus their phone number ...
11
votes
5answers
3k views

Why is my C# program slower than my Python program?

I made a program on python, and wanted it to be faster, so I wrote it on C#, because it's compiled. To my surprise, the python program is much faster. I guess there is something wrong with my C# code, ...
5
votes
3answers
295 views

WHERE NOT IN SQL Performance

SELECT TOP 1 l.ID FROM Leads l WHERE l.ID NOT IN (SELECT LeadID FROM LeadFollowups) AND l.ID NOT IN (SELECT LeadID FROM LeadsWorking) AND l.ID NOT IN (SELECT LeadID FROM LeadsDead) ...
3
votes
1answer
36 views

Check for similar value with SQL

I've two table (t1 and t2) with 3 identical integer columns : c1, c2 and c3. I want to count how many value in t1 are in t2 So I start to write : SELECT count(t1.value) FROM t1 INNER JOIN t2 ON ( ...
3
votes
1answer
23 views

“Histogram of Oriented Gradients” (HOG) feature detector for Computer Vision: trying to optimize for speed

Below is a function that I've only slightly modified from it's original context, found here. Before mentioning anything else, it should be noted that I'm desperately trying to optimize this code for ...
4
votes
1answer
51 views

Modified BFS code optimizations

I need some help reviewing this code in terms of making as fast as possible. This is a modified version of BFS that does quite a bit of processing on the side. Use case: I have a large graph ...
0
votes
0answers
17 views

How should I store a list of groups of webpages with metadata? [on hold]

I'm programming an entity-based web crawler, where I need to collect webpages on different people. Right now I'm iterating through a List of EntityWebpageBundles (a class I created with a label field ...
2
votes
2answers
34 views

Validating an input string against some enum fields

I have this enum below public enum TestEnum { h1, h2, h3, h4; public static String forCode(int code) { return (code >= 0 && code < values().length) ? values()[code].name() ...
5
votes
2answers
148 views

Optimization of file scanner

Program must to find duplicate files (by content) in a given directory(and subdirectories). I collect all data in Map<Long, ArrayList<String>> map where Key is the size of file and Value ...
6
votes
1answer
123 views

Solving the Reve's puzzle

I'm trying to solve the Reve's puzzle (a variant of the Tower of Hanoi puzzle with four pegs). This is what I've come up with so far: def solve(disk, source, temppeg1, temppeg2, destination): if ...
2
votes
0answers
16 views

Knuth's algorithm M that produces mixed-radix numbers

This is the C++ code of my implementation of Knuth's algorithm M that produces mixed-radix numbers: #include "visit.h" void algorithmM(vector<int>& m) { m.insert(m.begin(),2); const ...
4
votes
4answers
96 views

Save space occupied by 2D array

My goal is to save space occupied by 2D array (sea) that has 3 different values. Ocean sea; //Ocean class has member 'private int[][] oceanMatrix;' public final static int EMPTY = 1; public final ...
2
votes
2answers
44 views

Algorithms for traversing unordered tree

I have been doing some programming 'exercises'. I'm trying to come up with the most efficient algorithm for tree traversal. Consider the following function signature: CNode * CNode::find(int ...
1
vote
3answers
87 views

Lowest common ancestor in recursive tree traversal

LCA = Lowest Common Ancestor The following code finds the lowest common ancestor in tree of nodes, where a node can have two parents, left and right. The tree looks like this: J-K / \ ...
5
votes
1answer
78 views

JavaScript Sandbox Pattern

Based on this Stack Overflow question I came up with the following code. I'd like your general thoughts about it. Code style, functional, logical, disadvantages, just anything you can come up based ...
3
votes
0answers
39 views

Filtering function

#include <iostream> #include <fstream> #include <algorithm> #include <thread> #include <cmath> #include <sstream> #include <cstdlib> using namespace std; ...
5
votes
2answers
73 views

How to optimize population projections for speed?

I am currently working on a problem of an online judge (not a contest). The program must calculate how many years will require for the population A (which is always less than B) to be higher than B. ...
4
votes
2answers
266 views

Performing non-production analytics on data

I have the following Lua script which I use against my redis environment to perform some non-production analytics on my data. My dataset contains hundreds of millions of records, hence I want to make ...
8
votes
2answers
518 views

C++ vector implementation

I have tried to implement a basic vector type in C++, yet I am not sure if I can do anything any more efficiently. template < typename _Ty > class vector { public: typedef _Ty *iterator; ...
3
votes
1answer
60 views

Algorithm optimization on date calculation

I need to calculate the calendar week of a given date. Constraints: It should be properly calculated based on ISO 8601 if week starts on Monday It should calculate based on US standards if the week ...
3
votes
1answer
34 views

Counter in FASM assembly

I am making a simple counter in assembly. It counts to a billion and exits. However, the performance of this is really horrible. A Java application (that does the same) outperforms it by around 10x. ...
5
votes
2answers
104 views

Is my N-drome (variation of palindrome) checking program efficient?

An N-Drome is a string that is the same forwards and backwards when split into n-character units. For example, a string would be a 1-drome if and only if it were a standard palindrome. An example ...
4
votes
2answers
119 views

Retrieve and load playlists from YouTube

I have this code I am using in a private project. The following is a snippet of code I use to retrieve and load playlists from YouTube: for (feedEntry in a.feed.entry) { if ...
6
votes
3answers
87 views

Iteration to recursive function

In my first iterative algorithm, I do this for (auto &widget : controls.getWidgets()) { if (!widget->visible) continue; widget->draw(); for (auto &widget_component : ...
6
votes
3answers
249 views

Code reduction possible with modulo operator?

I'm trying to model a puzzle in order to resolve it with the Choco solver. One of the constraint I'm coding is cyclical (it's triplet which follow themselves) like the following example: ...
8
votes
1answer
115 views

Rotating greyscale images

For educational purposes I wrote a little piece of code to rotate greyscale images as "low level" as possible, that is, not using any rotate() function, but doing the math. I was wondering if it could ...
5
votes
1answer
63 views

What are your opinions on these small scripts?

I am new to JavaScript, and I was wondering if anyone can share their opinions on what I have done below: First of all, the following functions are all placed in a file called main.js and that file ...
0
votes
0answers
30 views

Approximating Date for a D3.js timeline + General Style comments

I've updated code from a couple weeks back so I've come back to get more feedback. The original post can be found over here. Here is the updated code: /* * @Author: Gowiem * @Date: 2013-12-17 ...
1
vote
2answers
30 views

Range Minimum Query Implementation in Scala

I would like to heat some feedback on this. I'm coming from a Java background and this is my first program in Scala. I solved Range Minimum Query problem. object Solution { def main(args: ...
6
votes
1answer
97 views

Strange performance difference

For exercise, I wrote this code: def BigPrime(numP, plist = [], x = 1, counter =0): while len(plist) <= numP: if x == 1 or x == 2 or x == 5: plist.append(x) ...
6
votes
1answer
66 views

Is this an efficient way of removing duplicate words from an unsorted list?

I was using brute force to remove duplicate words since the lists were really small. But I want a solution that won't become too slow if the input grows. This function creates a binary tree and ...
0
votes
1answer
28 views

Any suggestions for optimizing this code?

This code is for Android but I guess anyone can take a chance at it. It does what I want it to do. Just that I am not comfortable with its deep level of nesting and too much of value swapping. Can ...
8
votes
1answer
60 views

Help speeding up my first Bash script

This is my first more-than-1-line script. It takes an inputfolder and a file prefix and get all the files matching. For the first of the files, the script grabs the first line and appends an extra ...
5
votes
1answer
90 views

Optimization for add function in queue

I would prefer if more experienced users could give pointers on how I can optimize and think better when writing code. Using Homework Questions as reference, as this is a homework related question. ...
6
votes
1answer
42 views

Optimize YUV channel splitting function

The input pointer *data contains the data that needs to be split into different arrays and put in yuvInput. Each pixel is 32 bytes 4 * 8. Note the (j*4) to break it up per pixel segment. The 4th ...
3
votes
2answers
71 views

Optimising a LinkedList data structure - Part 1

I have implemented a linked list. I feel I overdid it with pointers, used old standards and C++11, and I ended with too many lines of code. I will make my quotations into two parts: one for the Node ...
6
votes
4answers
150 views

Most efficient way to populate a vector of integers with no duplicates

I am trying to populate a vector of integers with one billion random number. The only constraint is that there can be no duplicates in the array. #include <iostream> #include <algorithm> ...
5
votes
1answer
92 views

Validating HTML Form

I am trying to create a simple validation for forms. I am almost there, but there are few bugs and optimization errors that I am really struggling with. I'm looking for advice on how to make this ...
-1
votes
1answer
71 views

App for playing and recording video

I'm making an app using AVFoundation that is essentially a photo booth with a view to play a video and a view to display and record video. Right now I'm implementing all of the code in the ...
7
votes
1answer
76 views

Creating a thread for file transfer

I am creating an application in Java that runs at scheduled intervals and it transfer files from one server to another server. For SFTP I'm using jSch, and my server and file details came from ...
2
votes
1answer
299 views

Approximating/Sorting groups of dates into buckets + general JS patterns/style

Update: I've updated the code below pretty extensively and posted a new question over here. I'm working on a directed study project with a professor of mine helping him build out a Django based ...
2
votes
1answer
58 views

Dice notation roller in JavaScript

I have the following function, intended to take standard dice notation (XdY+Z) and return a (sort of) random number based on the input. Are there any bugs/bad ideas/optimizable sections I am missing? ...
7
votes
7answers
471 views

Better way to get shortest sequence

I want to get the shortest sequence to reach a number. Rules: A[0] is always 1 Either A[i] = A[i-1]*2 or A[i] = A[i-1]+1 For example, if my input number is 17, my output should be 6, because ...
5
votes
1answer
127 views

Converting List to a DataTable and/or DataSet Extension Methods

Can someone help me improve this code? I and trying to have a couple extension methods to convert strongly-typed lists to a DataSet and DataTable respectively. But... being so green to C#, I am not ...
2
votes
0answers
62 views

Increasing speed of parity check matrix

The code runs fine and takes 100s to complete it for 5 iteration. I need to reduce it to take less time with the same number of iterations. h = 324 by 648 matrix The code is that of FFT Belief ...
9
votes
1answer
101 views

Tic Tac Toe implementation in Objective-C

First off, here's the code: main.m #import <Foundation/Foundation.h> #import "PSBoard.h" #import "PSPlayer.h" #import "PSInputHandler.h" int main(int argc, const char * argv[]) { ...