1.
Below is a solution of first problem -
int SuccessorOfANodeInBST(Node N, int givenNumber)
{
if(N-rightChild != NULL)
return (int) N-rightchild-data;
int iNumberFound = 0;
Node K = ParentOf(N);
Node J = ParentOf(K);
while(1)
{
if(K == J-leftChild)
{
On 09-Dec-2010, at 1:28 PM, rajan goswami wrote:
1.
Below is a solution of first problem -
int SuccessorOfANodeInBST(Node N, int givenNumber)
{
if(N-rightChild != NULL)
return (int) N-rightchild-data;
Why this? The right child might not be the next immediate higher
O(2n) algo
1st traversal
calculate min
calculate sx=1^2^.^N
where N= no of elements
2nd traversal
fx=(A[1]-min+1)^(A[2]-min+1)...^(A[N]-min+1)
Now if sx=fx
Array is valid otherwise not
Array is called Valid if all the numbers appearing in A [1...N] are
consecutive numbers.
Code for question no.--2
#includestdio.h
#includeconio.h
#includetime.h
struct test{
clock_t endwait;
void (*print_ptr)();
};
void print()
{printf(\nHello World\n);}
void wait ( int seconds )
{
struct test *g=(struct test *)malloc(sizeof(struct test));
g-endwait= clock
Dave, thank You very much for yours information. Really, I want to
know a theorical big-O algorithm, mainly to interact with sparce
matrix. We see every day a new technic computation growing world
information, but I not seen a new and revolutionary multiply matrix
algorithm that take less than
@juver++ : Could you please elaborate your answer a little ... ?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
Algo:
In first traverse find the min and the max values.
if (max-min) not equals (N-1)
return false
In next traverse map each in a hashtable of size N where index=key-min. Now
in case of collision return false
return true
--
You received this message because you are subscribed to the Google
@jai
yeah, it can be done using count sort logic
but that will take O(n) extra space
which can be avoided by using XOR.
On Fri, Dec 10, 2010 at 3:34 AM, jai gupta sayhelloto...@gmail.com wrote:
Algo:
In first traverse find the min and the max values.
if (max-min) not equals (N-1)
return
I got the correct answer:
If it is a valid array, sum of all elements in the array = value
calculated using arithmetic progression formula
In this case
Sum of arithmetic progression = (n/2)[2*a+(n-1)*d}
where a = min of the array
n = number of elements
d = 1
If this value is equal to sum of
prims check for this case [1,1,4,4]
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For
my bad
The solution i quoted works only in case of no repititions.
Aditya solution is correct
On Dec 10, 9:23 am, mo...@ismu mohan...@gmail.com wrote:
prims check for this case [1,1,4,4]
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks
i did nt get this xor part in adithya solution
check if this works
array is valid if satisfy 2 conditions
1.max-min=n-1
2.there should be no repeatations
first one can be done in O(n)
for second
check 1xor2xor...xorn=(a[1]-min+1)xor(a[2]-min+1)xor..
if both are equal there are
997 is a prime number, so the calculation must be (1!+2!+...+996!) mod
997
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
@Dave
I like this. use mem just O(1) , my algo use O(N). Thxx
haxxpop
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
@jai gupta
why is this work??
I think it just calculates (N+1)! %n
haxxpop
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
15 matches
Mail list logo