Optimization is the act of improving a method or design. 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)

-2
votes
0answers
20 views

Comparing two values to two other values efficiently [closed]

So for an important piece in my code (thats getting called a lot) I need to compare 2 doubles (a and b) to 2 other doubles (x and y) to meet the following conditions: return false if both a and b ...
0
votes
1answer
38 views

Optimizing Diwali Lights problem in C

I was trying to solve the Diwali Lights challenge on HackerRank. Problem Statement On the eve of Diwali, Hari is decorating his house with a serial light bulb set. The serial light bulb set ...
4
votes
1answer
189 views

Optimizing critical loop for consuming a byte-buffer

I'm currently developing an Open Source project called sims3py using Python2.7. One overarching goal of the project is to ensure a Pure Python implementation of functions currently available only ...
2
votes
0answers
65 views

Minimum number of coins - (dynamic programming solution - topdown approach)

Given a list of N coins, their values (V1, V2, ... , VN), and the total sum S. Find the minimum number of coins the sum of which is S (we can use as many coins of one type as we want), or report that ...
0
votes
1answer
19 views

More efficient columnar transposition decryption

Below, I have created a rudimentary script to decipher a columnar transposition. I am wondering if there is a more efficient way to determine the number of the rows in a column? Also, is there a way ...
3
votes
2answers
105 views

Optimizing Multiplication Table

I have a class that takes an array of integers and produces a multiplication table. ...
1
vote
0answers
46 views

Minimum amount of edges that needs to be traversed to visit all vertices… or something like that

So I have this problem, where I'm given m connections over n vertices. The vertices are labeled ...
-2
votes
0answers
32 views

Better way to build an object (multiple methods)?

I've inherited a method that populates/builds an object (ReportSchedulesVO rsVO), and is about 300 lines long. At an overhead view, the purpose of the method is to ...
1
vote
1answer
36 views

GCD calculation - A cross of the Euclidean and the Binary algorithm

I was reading Knuth's The Art of Computer Programming - Volume 2 (Seminumerical Algorithms) Third Edition. I saw the two algorithms (A and B). A method (due to V. C. Harris) was mentioned (in page ...
2
votes
1answer
41 views

Building a Simple Menu With Perl

I wrote a Perl script to implement a simple menu where you can call subroutines for each menu option. I created a Menu class that can be used to create new menus and a print method that will start ...
8
votes
3answers
317 views

Two sets came to an intersection

Challenge: Print set intersections. Specifications: Your program should accept as its first argument a path to a filename. Each line in the file is a test case. Each test case contain ...
3
votes
0answers
62 views

Shortest path for every source-destination (s-d) pair in a network?

I am working on Dijkstra algorithm and trying to find the shortest path for every source-destination (s-d) pair in a network. I have the below code which is working fine. ...
1
vote
2answers
72 views

Project Euler - Smallest multiple

Here's Problem 5 - Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly ...
10
votes
2answers
179 views

Calculating holes on a Tetris grid quickly

I have created a Tetris AI which can play Tetris on its own given a set of rules. It places the next piece in every possible way on the board, and calculates which position that gives the fewest ...
3
votes
3answers
107 views
10
votes
4answers
2k views

TicTacToe AI needs optimization

How do I condense this gigantic monster into something more manageable? I heard about command pattern but I can't figure out how to use it. What other solutions are there? ...
4
votes
1answer
58 views

TicTacToe game needs optimizing

I'm new to programming and want to check if I'm using best coding practices in my program. ...
3
votes
0answers
20 views

Optimization for better response time to use in analytics application

We are trying to use NodeJS for analytics. The following code gets the parameter from a URL and dumps it into a flat file. Is there any way to optimize it to get better response time? ...
7
votes
0answers
114 views

Optimizing performance of slow complicated article-sorting query

In short I have a bunch of articles (~100k) which shall be ranked ("mixed", hence "newsmix") based on their newsValue (how important they are, between 1 and 10) and newsLifetime (how long they stay ...
15
votes
4answers
1k views

Duplicate like a weapon, arrays like heaven

Challenge: Find the duplicated entry. Specifications: Your program should accept as its first argument a path to a filename. Each line in this file is one test case. Each line ...
3
votes
1answer
46 views

Efficiency and correctness of my randomized selection algorithm

Instead of picking a random pivot I'm shuffling the array beforehand. Does it count as randomization and is it efficient to shuffle or pick a random pivot and is my implementation pythonic? Problem ...
4
votes
1answer
90 views

Optimizing code to find maximum XOR in Java

This problem is from HackerRank (not a competition, just for practice) Basically what you do is take in two integers as a range and then finding the maximum XOR from a pair of integers in that ...
2
votes
2answers
55 views

Commute info entry fragment for Android app

This is a simple app for taking down a user's home and work address, the days of their commute, and the times they go to work and go home. The times and workweek are entered via TimePicker dialogs ...
3
votes
2answers
63 views

Premium palindromic primes

Challenge: Write a program which determines the largest prime palindrome less than 1000. The answer is 929, and my program correctly finds and prints this, but actually ended up being more complex ...
2
votes
2answers
47 views

Quickly filter an object by keys

I am trying to optimize an object filter function. Given an array of keys, I need to filter an object. I feel that creating a new object each time may degrade performance. Is there a way to mock the ...
0
votes
1answer
67 views

PHP framework building: initializer and object loader classes

I am building a PHP framework and would like to get some feedback on a few different sections of the project. I consider myself still a neophyte in PHP so I would like to ask if I'm going about ...
1
vote
0answers
29 views

Optimize Python script for generating Point Cloud

I'm trying to produce a 3D point cloud from a depth image and some camera intrinsics. The image is 640x480, and is a NumPy array of bytes. The output is a (rows * columns) x 3 array of points. I've ...
2
votes
1answer
100 views

Dijkstra's algorithm in Python

I was hoping that some more experienced programmers could help me make my implementation of Dijkstra's algorithm more efficient. So far, I think that the most susceptible part is how I am looping ...
3
votes
0answers
29 views

Optimizing image generation in Perlin noise generator

I've created a simple Perlin noise generator in JavaScript and am trying to find ways to optimize it. It lives inside a webpage and generates an image using nothing more than random number generator ...
1
vote
2answers
51 views

Quicksort algorithm

I have reimplemented the quicksort algorithms that takes a list and sorts it in non-decreasing order: ...
1
vote
4answers
71 views

Coupon collector

This is a coupon collector code to analyze the running time. I need some suggestions on improving the running times of this code. I have used the data structure dictionary, but is there any other data ...
2
votes
1answer
28 views

CREATE Service Call

I'm a relatively new (~6 mos) developer, and I'm hoping for some feedback on my code style/structure. While I'm particularly interested in efficiency and maintainability, I'm open to feedback ...
5
votes
1answer
62 views

Effective use of branch prediction in terrain generator

I am trying to learn how branch optimization works. For an experiment, I have a recursive fractal terrain generation and I have moved all if statements to binary ...
4
votes
1answer
49 views

Data-checking class supporting letters

I'm starting to learn OOP with PHP, and all I've learned so far is just by searching and reading. So I have this need to check input data for certain things like min of chars, max of chars, spaced or ...
3
votes
3answers
195 views

Determining if a pair exists in a large sorted array

I'm doing practice interview questions from here. Here is the one I am currently on - if you are given a very large sorted int array, then check of there exists a ...
2
votes
3answers
415 views

Finding duplicates in two sorted arrays

This is an interview question from here. Specifically, the second asked for a function that took in two sorted arrays of integers with no duplicate values within a single array and which returned an ...
3
votes
3answers
116 views

Project Euler 35: Circular primes below 1 million

I'm doing another Project Euler problem, number 35, and I need help improving my code speed: The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
2
votes
0answers
23 views

One-dimensional convolution using Data.Vector

As part of some code I've written, I needed to perform a 1-D convolution. This convolution ends up happening quite often, so I wanted to optimise it (in some way other than using a FFT, though I could ...
8
votes
3answers
203 views

Breadth-first search for clusters of pixels in a given color range

I am a beginner in programming languages, so I apologise if my code is badly formatted or doesn't make any sense. My program gets an image and a RGB color range as input and it counts how many pixels ...
-1
votes
1answer
59 views

Merge sort optimization and improvement

How to optimize this merge sort code to make it run faster? And how to call merge_sort function without user input by declaring necessary array in the code? ...
3
votes
1answer
97 views

Wait for System.IO.StreamReader.ReadLineAsync

I want to wait for a line to be read, but only for so long before timing out. This is what I came up with. Is there a better way to do it? ...
2
votes
1answer
48 views

Is this an optimal implementation of merge sort?

I am taking an algorithm course and we are to implement merge sort that handles list of elements with even or odd number of elements and handles duplication, so I wrote this function: ...
6
votes
3answers
154 views

Chess puzzle improvement

Is it possible to optimize this solution to the N-queens puzzle? ...
3
votes
3answers
125 views

Find intersection of two arrays without duplicates

A = [9, 1, 4, 2, 5] k unique integers B = [3, 1, 8, 7, 6, 5] n unique integers Intersection => [1, 5] Find an algorithm that uses \$O(1)\$ space (the space used by the return variable is not ...
-4
votes
1answer
66 views

Is this a better loop? [closed]

My team has a lot of code written with fairly traditional for-loops: for(int i=0; i < Something.GetSize(); ++i) { /* do work */ } But recently, some devs ...
3
votes
1answer
95 views

Check if string can be rearranged into a palindrome

I created a function to test whether a single word string can be a rearranged into a palindrome (doesn't have to be a real word). My logic was if the string has an even number of letters, then each ...
5
votes
3answers
137 views

Bresenhams line algorithm optimization

Based on these guidelines I optimised Bresenhams line algorithm, it now fits for all kinds of line cases like images a, b, c, d, e, f, g, h show in those guidelines. This is my test.txt input file ...
5
votes
3answers
112 views

Counting letters as quickly as possible

I received a task, of taking a known text file (Linux dictionary), use threads to count the different letters in it, and present the results in an array. The code doesn't have to be pretty, elegant, ...
3
votes
2answers
112 views

Implementation of Dijkstra's algorithm to find the shortest path in graph

This is my implementation of Dijkstra's algorithm in C++. Please clarify Whether the class design is proper or if it needs to be improved. I am just hard coding the vertex based on the priority of ...
2
votes
1answer
43 views

Books Algorithm Dealing with Square Digit Sums

A little context: Book has 411 Pages Read a random number of pages on the first day which is unknown Number of pages to read next day is the square of the sum of the digits of the page ...