Do the two algorithms have the same theta characterization of Θ(n^2)?
int sum = 0;
for (int i = 0; i < n; i++ )
for (int j = 0; j < n * n; j++ )
sum++;
int sum = 0;
for ( int i = 0; i < n; i++)
for ( int j = 0; j < i; j++)
sum++;
If not then does this mean that this characterization is not Θ(n^3)?
int sum = 0...
Hi,
I am wondering if there is a way to generate a key based on the relationship between two entities in a way that the key for relationship a->b is the same as the key for relationship b->a.
Desirably this would be a hash function which takes either relationship member but generates the same output regardless of the order the members ...
I have a list with length N and each element of this list are 0 or 1.
I need to get all possible combinations of this list. Here is my code:
def some(lst):
result = []
for element in lst:
c1 = copy.copy(element)
c2 = copy.copy(element)
c1.append(0)
c2.append(1)
result.append(c1)
...
Hi there. We're currently creating a simple application for image manipulation in Silverlight, and we've hit a bit of a snag. We want users to be able to select an area of an image (either by drawing a freehand line around their chosen area or by creating a polygon around it), and then be able to apply effects to the pixels within that s...
I need to create a Monte Carlo simulator for some financial transactions. The inputs would be:
the average percent of transactions that end up profitable
the average profit per transaction
the number of transactions per time period
I've looked at the Math::Random::MT::Auto Perl module but am unsure how to formulate the inputs to the...
I trying find a simple python-based algorithmic ranking system.
Here's the scenario:
There will be 30 levels, level 1 starts at 0 points. 2000 points are required to achieve level 30.
More points will be required as the levels progress.
For example, to go from level 1 to 2 might take 3 points. Level 2 to 3 might take 5 additional poi...
Hi everybody,
I am looking for a fast implementation of the "arrangement" algorithm (permutation with duplicates).
Given N objects (A in quantity a, B in quantity b, ...), generate all the possible combinations.
Exemple:
Arrangement("AAA", "B", "CC") would return :
"AAABCC" "AABACC" "AABCAC" "AABCCA" "ABAACC" "ABACAC" "ABACCA" "A...
There are a variety of web sites that purport to offer reusable code in some fashion (Krugle, Koders, byteMyCode, et al). These are great for browsing and for learning by reading other people's code, though I find it challenging to actually find something specific.
With O'Reilly's cookbook series (Perl Cookbook, Ruby Cookbook, C# Cookbo...
Hi, I'm currently implementing a navigation system for routing through Europe. So far, I have shortest path implemented (Dijkstra and A*). It was the easy part, now I need some algorithm for fastest path. It has to be fast and reliable.
I know it can be done just by assigning values to a road quality (for example 1 highway, 2 main roa...
I'm helping a professor for some lectures in OO and numerical algorithm in particular problem like to find the root of a function, minimization, interpolation, ... the problem is that he wants to teach at the same time OO with C++. I think that usual algorithms like these are implemented using procedural programming, at least you can use...
I'd like to produce fast random shuffles repeatedly with minimal bias.
It's known that the Fisher-Yates shuffle is unbiased as long as the underlying random number generator (RNG) is unbiased.
To shuffle an array a of n elements:
for i from n − 1 downto 1 do
j ← random integer with 0 ≤ j ≤ i
exchange a[j] and a[i]
But...
Ive got a bit stuck figuring it out for the negative direction? it must be really simple, but just cant seem to get it!
x = current x position
dir = direction of motion on x axis
if (tween == 'linear'){
if (dir == 1) {
x += (x / 5);
}
else if (dir == -1){
//what here??
}
}
...
The postage stamp problem is a mathematical riddle that asks what is the smallest postage value which cannot be placed on an envelope, if the letter can hold only a limited number of stamps, and these may only have certain specified face values.
For example, suppose the envelope can hold only three stamps, and the available stamp values...
I have vector street map data in 2D format as below:
polyline0:
dataX = {x00,x01,..,x0n}
dataY = {y00,y01,..,y0n}
polyline1:
dataX = {x10,x11,..,x1n}
dataY = {y10,y11,..,y1n}
polyline2:
dataX = {x20,x21,..,x2n}
dataY = {y20,y21,..,y2n}
...
polylinem:
dataX = {xm0,xm1,..,xmn}
dataY = {ym0,ym1,..,ymn}
I can draw polyline0, polyline1,...
I am writing a program that is a word search solver and was curious if there was a better approach than what I was taking. The program contains a grid of characters that are suppose to be the puzzle followed by a line break and words to be located in the matrix.
My question is that in locating for the beginning and ending characters o...
Alright, this might be a tricky problem. It is actually an analogy for another similar problem relating to my actual application, but I've simplified it into this hypothetical problem for clarity. Here goes:
I have a line of rods I need to be sorted. Because it is a line, only 1 dimension needs to be of concern.
Rods are different l...
I try to design my app to find database entries which are similar.
Let's for example take the table car (Everything in one table to keep the example simple):
CarID | Car Name | Brand | Year | Top Speed | Performance | Displacement | Price
1 Z3 BMW 1990 250 5.4 123 23456
2 ...
This problem sounds simple at first glance, but turns out to be a lot more complicated than it seems. It's got me stumped for the moment.
There are 52c5 = 2,598,960 ways to choose 5 cards from a 52 card deck. However, since suits are interchangeable in poker, many of these are equivalent - the hand 2H 2C 3H 3S 4D is equivalent to 2D 2S ...
Given that we have this kind of string "XXXXXXX XXXXX 756", "XXXXX XXXXXX35665", (X is a character), which is the fasted way to get the number in the end of string?
EDIT: well, this is just-for-fun question. Solve this is quite simple, but I want to know the fastest algorithm to archive this. Rock it on!
...
Given n points in a plane , how many squares can be formed ...??
I tried this by calculating the distances between each 2 points , then sort them , and look for the squares in the points with four or more equal distances after verifying the points and slopes.
But this looks like an approach with very high complexity . Any other ideas ...