It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
Given two sorted arrays, A and B, find i,j for which |A[i] - B[j]| is minimum.
Since the arrays are sorted, you can pass through them with 2 pointers (one for each array). If |A[i+1] - B[j]| < |A[i] - B[j+1]| then increment i, otherwise increment j. Continue until you've reached the end of one of the arrays. Keep track of the minimal indexes as you go.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
If we have an algorithm which is order N^2*logN, and if it takes 1 ms with input size 64; does it take 2^10*(11/6) ms to run this algorithm with input size 2048? I am using direct proportion here, that's why it seemed defective to me.
Easiest way to solve is probably to divide 2048 by 64, plug the resulting number into the complexity equation, and the result is the number of milliseconds for Input size 2048.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
You have a continuous stream of numbers coming in. You don't have space to store them all. But devise a mechanism by which at any point of time you select any number with equal probability.
Have space for one number, and for the nth number replace it with that number with probability 1/n.
http://en.wikipedia.org/wiki/Reservoir_sampling
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How will you compute x/y in O(log(n)) time.
n=x/y, x & y are integers
You can't use the / operator.
One implementation is to add y q times till the result is less than x i.e.
y * q < x
What about 10**(log(x) - log(y))
Big O() notation only applies to how a problem scales with different number of inputs.
The question doesn't make sense unless you mean 'n' is the number of digits in x and y
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
In plain English describe the algorithm for an insertion sort of items in an array.
I've also been asked to use diagrams if appropriate but that's a little hard on here I understand.
Here is a PDF presentation which describes insertion sort.
With a quick google search http://en.wikipedia.org/wiki/Insertion_sort
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have n numbers (could be a list or array of n numbers).
Given a number k I want to return a quadruplet of numbers (a,b,c,d) thus that
a+b+c+d=k.
Time Complexity: O(n^2) in average (probability).
You might find this useful: http://en.wikipedia.org/wiki/Dynamic_programming
Think about how to break the problem into subproblems.