nirojpokhrel
BAN USERorder statistics with rank n-3.
can be solved in O(n) time.
However, is it any better than O(3n)? Maintaining a buffer to hold three elements sounds better because we don't have to participate and call recursively which is pretty expensive by itself.
i think the simplest way for inter-thread communication is to use the global variable.
- nirojpokhrel November 22, 2012Ask one of the guard:" what would the other guard say if i ask him which way is the hell?"
And whatever answer he gives that is the way to heaven.
Explanation:
If you end up asking the question to the truthful one, he will tell the true and he knows the other guard is going to lie so he will so the way to heaven.
If you end up asking the question to the liar he will lie what the answer will be and he lies and instead shows the way to heaven.
In the second thought, what is the purpose on sorting when you know all the n elements are presents. So, just store 1 ... n in the set and it will be sorted if I understood your problem properly.
- nirojpokhrel November 20, 2012simply use the counting sort if u want to do it in O(n) time. Insertion sort is quite slow.
- nirojpokhrel November 20, 2012
great solution. But I have a doubt though, does this line gives the approximated line which in average is closest to all the points. Does this line confirms maximum number of points passing through it ?? Say we have 17 points, 10 of them can be drawn in a line but rest of the 7 points will lie way below the line then. In this case I don't think the line will pass through those 10 points but it tries to find the minimum error from all the points if I am right ??
- nirojpokhrel November 24, 2012