Given an unsorted integer array, and without making any assumptions on
the numbers in the array, Is it possible to find two numbers whose
difference is minimum in O(n) time.
Edit: Difference between two numbers a, b is defined as abs(a-b)
I don't know if this is possible, but still?
...
The powerset of {1, 2, 3} is:
{{}, {2}, {3}, {2, 3}, {1, 2}, {1, 3}, {1, 2, 3}, {1}}
Lets say I have a Set in Java...
Set<Integer> mySet = new HashSet<Integer>();
mySet.add(1);
mySet.add(2);
mySet.add(3);
Set<Set<Integer>> powerSet = getPowerset(mySet);
What I want is the function getPowerset, with the best possible order of complex...
We have a part of an application where, say, 20% of the time it needs to read in a huge amount of data that exceeds memory limits. While we can increase memory limits, we hesitate to do so to since it requires having a high allocation when most times it's not necessary.
We are considering using a customized java.util.List implementatio...
I'm using Espresso to produce a minimized form of a set of boolean equations. However rather than generating logic for a programmable array logic (which is what Espresso is normally used for), I am looking to implement these on a standard microprocessor. The trouble is that Espresso produces output in conjunctive normal form, which is pe...
Hi
I want to apply the concepts I have studied in algorithm and artificial intelligent in my project. So can any one provide me a sample application example where did can I apply?
I have taken courses algorithm and AI. Some of the courses I had taken include
Divide and conquer
Dynamic programming
Backtrack
Greedy Algorithm
..Etc
My m...
I have written a SAT solver for 2-satisfiability problem,someone please provide me a test case with say 10000 literals which has only one satisfiable assignment i.e only one solution
The format can be:(for 3 literals)
2 // No of clauses and then each clause
2 3
1 -2
corresponding to
(b+c).(a+!b)
...
I am looking for an existign path truncation algorithm (similar to what the Win32 static control does with SS_PATHELLIPSIS) for a set of paths that should focus on the distinct elements.
For example, if my paths are like this:
Unit with X/Test 3V/
Unit with X/Test 4V/
Unit with X/Test 5V/
Unit without X/Test 3V/
Unit without X/Tes...
I ran into this date and time constraint problem earlier this week, and haven't really found any good approach for an algorithm. Each idea I get grinds to a halt with something like what if this is a leap year? or what if this is run on the night when we change to/from DST
Input: A crontab expression (wikipedia on CRON format,Cron). F...
How does one find the rank of each element of an array, averaging in the case of ties, efficiently? For example:
float[] rank(T)(T[] input) {
// Implementation
}
auto foo = rank([3,6,4,2,2]); // foo == [3, 5, 4, 1.5, 1.5]
The only way I can think of doing it requires allocating 3 arrays:
A duplicate of the input array because...
I have four std::vector containers that all might (or might not) contain elements. I want to determine which of them has the most elements and use it subsequently.
I tried to create a std::map with their respective sizes as keys and references to those containers as values. Then I applied std::max on the size() of each vector to figure ...
I'm facing tho following problem:
let's say u is a social network user and as such has a list of friends, F(u). a partition is a function F->G, where G is a set of groups such as High-school, university, work, etc'.
I need to come up with algorithm to partite F:
the input is F and also F(f) for every f in F (the list of friends for eac...
We've got a bunch of data the users may want to view windows of and do so quickly. They may want to look at a window of the data that is a day, a week, a month, or an arbitrary beginning and ending data. Sorting and summing up all of this stuff in real time is proving to be painful for us so I got the idea of doing something similar to M...
I have a library of linked list/binary tree methods for use when standard containers don't fit - e.g. when there are different types of nodes, or when I need to convert from binary tree to list and back again. It includes red-black tree handling.
One of the methods converts from a double-linked list to a perfectly balanced simple binary...
What are the suitable data structures for graphs ?
I guess the answer varies on the type of graph?
in any case, any recommendations?
...
Hi,
I got array of some (about 200) colours in RGB format. I want to write program that taking any RGB colour and trying to match colour from my array that is most "similar".
Of course I need better definition for "similar". Unfortunately I don't have any. It want it to act like a parson asked the same question.
I want to show some inf...
mystery(int A[1..n], int n) {
// pre: n is a power of 2 for i=1..n {
for i = 1...n {
A[i] = A[i] + 1;
}
if (n>1) mystery(A, n/2);
}
}
I think the worst case, it runs in O(n), am I right?
Edit: This is from another old exam (which has answers for us), but the following algorithm runs...
Martin Fowler has a Money class that has a money allocation routine. This routine allocates money according to a given list of ratios without losing any value through rounding. It spreads any remainder value over the results.
For example, $100 allocated by the "ratios" (1, 1, 1) would yield ($34, $33, $33).
Here is the allocate functio...
I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "misc"-unit:
function cwLeftPad(aString:string; aCharCount:integer; aChar:char): string;
var
i,vLength:integer;
begin
Result := aString;
...
What is the most efficient way to generate all the combinations, dispositions and permutations of an array in PHP?
...
Hi, I need to calculate the number of matches in a Swiss system tournament, is there any library in php that can help me?
...