Given an array A of N nonnegative numbers, I'm interested in finding the number of ways you can pick 5 numbers (from distinct positions in the array) such that their sum is S.
There is an easy solution in O(N^3):
Let H be a hash table of (sum, position of leftmost element of sum)
for i = 0, N
for j = i + 1, N
H.add(A[i] + A...
Hi guys,
Currently, I am working on a project that is trying to group 3d points from a dataset by specifying connectivity as a minimum euclidean distance. My algorithm right now is simply a 3d adaptation of the naive flood fill.
size_t PointSegmenter::growRegion(size_t & seed, size_t segNumber) {
size_t numPointsLabeled = 0;
/...
This is a pretty simple problem im working on in Ruby, but im a total noob so I want to learn the most correct solution. I have a list of data with a name and a value. I need to remember all those (obvious answer: hash). But, i also need to remember the order of this data. SO it looks like:
x=1
y=2
z=3
I was thinking about making an a...
Let's say I have players table. It consists with 3 rows(it has much more, but let's suppose it has only 3). member_id, name, exp. I use member_id row in every page so that's why I added index only to member_id. But I want to make a top players' list in one page with the highest exp. So I do something like that:
$query = mysql_query("SEL...
I am using SQlserver procedure and i have habit of using of Print Statement in PRocedure
to differentiate the code of PRocedure.
I have almost 200-250 procedure in my DB.
Should print statement affect the Performance?
I am working on MultiUser Windows application.
...
I want to create a fairly simple mathematical model that describes usage patterns and performance trade-offs in a system.
The system behaves as follows:
clients periodically issue multi-cast packets to a network of hosts
any host that receives the packet, responds with a unicast answer directly
the initiating host caches the responses...
Hi i want to optimize the following code. It tries to find all coprimes in a given range by comparing them to n. But i want to make it run faster... any ideas?
#include <iostream>
using namespace std;
int GCD(int a, int b)
{
while( 1 )
{
a = a % b;
if( a == 0 )
return b;
b = b % a;
if( b == 0 )
retur...
I'm looking for the fastest way to popcount on large buffer of 512 or more bytes. I can guarantee any required alignment, and the buffer size is always a power of 2. The buffer corresponds to block allocations, so typically the bits are either all set, none set, or mostly set favoring the "left" of the buffer, with occasional holes.
Som...
I have a 22 machine cluster with a common NFS mount. On each machine, I am able to start a new MySQL instance. I finished creating a table with about 71 million entries and started an ADD INDEX operation. It's been more than 12 hours and the operation is still going on. So what I logged onto one of my other machines in the cluster, start...
I have a problem with describing algorithm for finding maximum rectangular area of binary data, where 1 occurs k-times more often than 0. Data is always n^2 bits like this:
For example data for n = 4 looks like:
1 0 1 0
0 0 1 1
0 1 1 1
1 1 0 1
Value of k can be 1 .. j (k = 1 means, that number of 0 and 1 is equal).
For abov...
Hey guys, I had some questions about using inline. I have been told to use it on small functions that I use a lot but I want to understand exactly how it works. Here is just a snippet of how I use it.
static inline point3D createPoint3D(GLfloat x, GLfloat y, GLfloat z){
point3D newPosition;
newPosition.x = x;
newPosition.y = y;...
let's say I have the following code:
for a in object.a_really_huge_function():
print a
In order to prevent a_really_huge_function from running multiple times, I am used to doing this in other languages:
a_list = object.a_really_huge_function()
for a in a_list:
print a
Is that necessary in Python? Will the part after in run ...
Is there a good tutorial out there how to speed up/refactor SQL Queries? I googled a bit, but did not find anything useful.
Thanks :-)
...
Hi,
I am working on a web portal (PHP/MYSQL) which have 3 sections photos, videos, articles. Each section has its own submission form using which user will submit photos, videos or articles corresponding to their accounts.
So, that URLS which I thought should be like
http://example.com/
http://example.com/about/
http://example.com/c...
Hi,
My work uses a great number of a class instances.
For a memory optimization, I would like to know if the using of static method will be better than simple functions.
Thanks for any suggestion around the optimization of managing lots of objects.
...
Hi,
I write the following Haskell code which take a triplet (x,y,z) and a list of triplets [(Int,Int,Int)] and look if there is a triplet (a,b,c) in the list such that x == a and y == b if it is a case i just need to update c = c + z, if there is not a such of triplet in the list I just add the triplet in the list
-- insertEdge :: (In...
Is there any portable way of doing branch prediction hints? Consider the following example:
if (unlikely_condition) {
/* ..A.. */
} else {
/* ..B.. */
}
Is this any different than doing:
if (!unlikely_condition) {
/* ..B.. */
} else {
/* ..A.. */
}
Or is the only way to use compiler specific hints? (e.g....
I have the following query:
SELECT AVG(val) from floatTable
WHERE tagindex IN(1,2,3,4)
AND DateAndTime > '$first_of_year'
It returns the average value for all the values measured for those four tags for the year to date. Since I'm already retrieving this data, how can I get the data since the first of the month, since the first of the...
I know that add is faster as compared to mul function.
I want to know how to go about using add instead of mul in the following code in order to make it more efficient.
Sample code:
mov eax, [ebp + 8] #eax = x1
mov ecx, [ebp + 12] #ecx = x2
mov edx, [ebp + 16] #e...
Is there any article/link available where I can find examples of SQL tuning(Oracle). It would great if it is explain with example. I need something like existing query, statstics, plan and then suggested query/recommendation and new plan.
I found couple of really good links on google:
http://www.dba-oracle.com/art_sql_tune.htm
http://...