Arulmozhi
BAN USER- 0of 0 votes
AnswersTechniques to shuffle an array?
- Arulmozhi in United States| Report Duplicate | Flag | PURGE
Algorithm
Time Complexity - O(n)
2 pointer approach. one starts at the end of the array and other at the end.
1) if sum ( a[first pointer] , a[second pointer]) > N move second pointer left
2) if sum ( a[first pointer] , a[second pointer]) < N move first pointer right
keep moving untill 2 pointers meet each other.
improving Anonymous idea
Using Binary Semaphore bMutex where
false means no thread has acquired.
true means thread has acquired a lock.
static bool bMutex = false;
int Signal()
{
if( bMutex == false)
{
bMutex = true;
return 1;
}
else
{
WaitforSignal();
}
}
//Thread will release the lock and go to sleep mode untill signalled
int Wait()
{
if( bMutex == true)
{
bMutex = false
}
SignalWaitingThreads();
return 1;
}
This pseudo code could be improved
- Arulmozhi July 05, 2012
simple inorder() traversal will give it.
- Arulmozhi February 21, 2013