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)

3
votes
3answers
74 views

SQLite insert code optimization

I just started working with SQLite in C# to test various features of an application. In building my first SQLite example I wanted to insert a large csv into a table (Person) with two columns, A and B. ...
1
vote
1answer
33 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
2answers
27 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
30 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
84 views

N-Queens optimization

Is it possible to optimize this solution to the N-queens puzzle? ...
3
votes
3answers
68 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
56 views

Is this a better loop? [on hold]

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
39 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 ...
4
votes
2answers
78 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
104 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
60 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
33 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 ...
1
vote
2answers
63 views

Book pages algorithm dealing with digit sum and squares [closed]

I would like some help condensing this code to make it more efficient. Could someone also help me output the number of pages she reads instead of the page number she is on... ...
4
votes
1answer
65 views

Water generating waves and reflection

For the last few days I have been working on wave generation script. As there are a lot of calculations involved I was looking for possible optimizations to improve the performance of the code. This ...
6
votes
4answers
2k views

Swapping two integer numbers with no temporary variable

I tried to swap 2 integer numbers without using an additional variable as a traditional swap. Is it legal in C++? My VC compiler doesn't complain nor gives any warning about it. If so, how can I ...
8
votes
1answer
132 views

Python-based Git pre-commit hook to manage multiple users/Git identities

A couple of months ago I posted a bash script to manage multiple Git identities as a solution on Stack Overflow but soon found the hook isn't flexible enough. Thus I decided to rewrite the hook in ...
5
votes
1answer
44 views

Kendo grid optimization

I have two kendoGrid(s) named: ...
18
votes
8answers
1k views

Optimize custom double.parse()

In my company's code, they use double.tryParse() which is quite good but sets too much security for our needs. As we sometimes have to parse a few billion strings, ...
2
votes
1answer
31 views

SQL query to order by the difference between FIRST and BEST scores

Can anyone help me optimise this query? I have the following table: ...
2
votes
3answers
119 views

Calculate the square root of the sum of the squares of the prime factors of an input number

This question is related to another one that I have asked here. I need to find ways to improve the runtime performance of the following piece of C-code. I want to increase ...
1
vote
1answer
62 views

Executing URL using Apache HttpClient

I have XML below which is stored as a String in xmlData variable and I need to pass this String to my URL in ...
5
votes
2answers
134 views

Knight's Tour with Heuristics

When someone suggested that I solve Knight's Tour, I did so with heuristics and recursion. It takes a lot of time to solve even a 8x8 board: N-A1 N-C2 N-E1 ... N-E6 N-F4 Time ...
0
votes
2answers
52 views

Modulo problem code

This prints out the sum of the numbers that have same remainder and quotient according to the input number. It's an online judge problem, and it currently throws a time-out since it's taking too long. ...
1
vote
1answer
72 views

Very slow graph walking

My code is very very slow. Could you give me hints on how I can make it much faster? ...
2
votes
4answers
64 views

Selecting three stylesheets in a specific order

I'm somewhat new to SQL (only had to use it in Database classes). I have a simple table of stylesheets, from which I want to select specific ones in a specific order (e.g. reset, then layout, then ...
6
votes
2answers
82 views

Name filtering in Java

I have a search box for searching for people in a list of names. Here is the code that runs every time the query changes. I could not find anything open-sourced for this, so I wanted to make sure ...
4
votes
0answers
61 views

Optimization of sparse matrix multiplication for billion by billion matrices

I have to do multiplication of two billion by billion sparse matrices (on a CPU), hence any help or hints in optimizing the below given code would be extremely useful. Note: I am only showing the ...
1
vote
1answer
37 views

Python Koans multiplayer Greed Game (dice)

I finished the Python Koans because I wanted to practise Python and I completed the extra assignment which is the Greed Game (see the rules here). Here is the code, I think there are no flaws but you ...
3
votes
0answers
59 views

Project Euler #14 — longest Collatz sequence

I was reading this question and realized that I didn't know Python well enough to critique the algorithm. So I wrote a Java solution instead, which is inappropriate for that question. Since there's ...
1
vote
3answers
58 views

Python greed roll

I am doing the Python Koans to practise Python a bit more and I got to the greed dice project. It is a very simple dice game that scores a set of up to five rolls. These are the rules: ...
4
votes
2answers
108 views

Importing different type of files into Lists

I am using a recursive directory scan to find all objects inside a Unity3D project. After that, I wish to move all these files to a sorted List. Is there a cleaner ...
3
votes
1answer
62 views

Project Euler #14 (Longest Collatz sequence)

A Collatz sequence for a given positive integer \$n\$ is to take half of \$n\$ if even and \$3n+1\$ if \$n\$ is odd; repeat until the value goes to \$1\$. The question is which number from 1 to ...
6
votes
3answers
312 views

Optimizing an Anagram Solver

I've built an anagram solver in Python 2.7. It goes through a text file with over 100,000 words and checks if any permutations of the input matches the line. It works great, except it is very slow. ...
5
votes
4answers
394 views

Project Euler #12 - first triangle number with more than 500 divisors

I tried to solve Project Euler 12 with a first very naive solution by myself. It took nearly 30 minutes to run until it found the solution. Then I made a change in the function ...
1
vote
0answers
38 views

AI for an online contest

I'm actually creating an AI for the online contest Vindinium. The fact is that's also an exam for my school because I'm going to have a note with that work. I created an AI based on ants pheromones ...
2
votes
1answer
47 views

Checking if a directory exists in FTP without relying on exception handling?

I've written a method to check if a directory already exists on an FTP server. The only way I could see to make this work was to return a different result from the method if an exception is thrown - ...
1
vote
1answer
35 views

Prime Number Sieve Optimization

I've written my own prime number sieve in JavaScript. It loops through numbers 1-100 and puts them in one of two arrays, depending on if it is composite or prime. I was wondering if there are any ...
4
votes
1answer
122 views

Search algorithm to find a point from a given X value

I implement the following algorithm in order to find a point from a given X value in a sorted list with the same distance between each X values. Here's an example of my list content with a delta of ...
5
votes
3answers
94 views

Stepping Number Solution Optimization

I have the following problem: The stepping number: A number is called a stepping number if every adjacent digits, except those separated by commas, differ by 1. A stepping number can't be a ...
3
votes
1answer
63 views

EF GroupBy query optimization

I have this method: ...
2
votes
1answer
73 views

Calculate possible balances in piggy-bank by weight

I have solved Piggy-Bank problem on SPOJ using dynamic programming. The question asks you to get the minimum value that is possible with given weight (\$w\$) and one or more coins (\$n\$) with given ...
1
vote
0answers
23 views

Python, testing user input speed with random phrase [closed]

This is a plugin for a Jabber/XMPP bot which gives the user a random phrase, and starts a timer in milliseconds, when the user replies with same phrase, the bot replies with the timer. Now these the ...
8
votes
4answers
251 views

Count cars passing in opposite directions

The problem comes from codility, whose coding problems I'm starting to enjoy as their evaluation criteria really looks at runtime. Task description A non-empty zero-indexed array ...
5
votes
0answers
58 views

Smoother column resize, page reveal animation

I've been working on this site. The designers original inspiration for the column layout came from this site. I've been trying to get the animation as smooth as possible, to match the smoothness of ...
11
votes
3answers
128 views

Becoming the greatest tower builder

I am trying to learn how to write proper code in python, and stumbled upon the following problem. Bob is given a set of building blocks b, and a number ...
2
votes
2answers
41 views

Randomly pick a host from a list, subject to an uptime requirement

I have a POJO as shown below which will have hostname and other attributes. ...
3
votes
1answer
72 views

Recursively parsing JSON response using GSON

I have a URL which I am executing it and it is returning the below string as a JSON response. I am using GSON to parse JSON. In the below JSON, "resourceId" ...
5
votes
2answers
102 views

My Google Maps Script

I've written a script with the Google Maps JavaScript API v3. I've ran it through JSHint and everything seems to be valid. I'm wondering if my script has room for improvement. Any suggestions are ...
7
votes
2answers
175 views

Refactoring a FTPHelper Class

I've written a FTPHelper class to help teach me more about code strucutre. I don't know what I don't know so I would really value feedback on how I can be laying out and thinking about my programming ...
2
votes
0answers
33 views

Speeding up loop-rich Matlab function to calculate temperature distribution

I would like to speed up this function as much as possible in Matlab. This is part of a bigger simulation project, and as it is one of the most called functions within the simulation, this is crucial. ...