Re: [algogeeks] Permutation of Array.

2010-08-23 Thread BALARUKESH SIVARAMAN
now its clear.. thank you.. -- 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 more

Re: [algogeeks] Permutation of Array.

2010-08-21 Thread BALARUKESH SIVARAMAN
@Nikhil I am clear with your first 2 algos but not with the change u introduced ie., adding a check. please give a working example -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Permutation of Array.

2010-08-19 Thread BALARUKESH SIVARAMAN
@Divya : Does the algo you gave work for the set { 6,5,9,111} ? I hope it doesnt... Correct me if i am wrong -- 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

[algogeeks] Abstract computer

2010-07-24 Thread BALARUKESH
You have an abstract computer, so just forget everything you know about computers, this one only does what I'm about to tell you it does. You can use as many variables as you need, there are no negative numbers, all numbers are integers. You do not know the size of the integers, they could be

[algogeeks] Bitwise Ternary operator

2010-07-21 Thread BALARUKESH
Ternary operator- x? y : z Implement it in a function: int cond(int x, int y, int z); using only ~, !, ^, , +, |, , no if statements, or loops or anything else, just those operators, and the function should correctly return y or z based on the value of x. You may use constants, but only 8 bit

Re: [algogeeks] Re: unique number in an array

2010-06-15 Thread BALARUKESH SIVARAMAN
XOR has the following problem... assume array is 2,3,3,2,1,2 here the unique element is 1 but using XOR we get 2^3^3^2^1^2=3 XOR works only when all the elements except the unique element occur even number of times. -- You received this message because you are subscribed to the Google

Re: [algogeeks] Re: unique number in an array

2010-06-14 Thread BALARUKESH SIVARAMAN
sort the input and then compare each element i with its adjacent neighbors ie., i-1 and i+1 if both are different then that element is the unique one... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Mirroring Binary Tree Pattern Problem

2010-06-13 Thread BALARUKESH SIVARAMAN
try this one.. make a level order traversal and store the elements in array... on the other system reconstruct it using right element for the left and left element for the right... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Problem with Virtual Function

2010-06-13 Thread BALARUKESH SIVARAMAN
In the first post the problem was that m_speed is not public also u should access m_speed using Scope resolution operator as m_speed is not a member of B. class A { public: virtual int speed()=0; int m_speed; }; class B:public A { public: int speed() { return A::m_speed; } }; For ur second

Re: [algogeeks] file handing

2010-06-13 Thread BALARUKESH SIVARAMAN
For the 1st qn.. the o/p will print the code in the file and then print an infinite sequence of empty spaces. the reason is... In C EOF is defined to hold a value -1 which when assigned to unsigned becomes 255. So it goes in an unending loop even after encountering the end of file. In second qn..

Re: [algogeeks] Re: infix

2010-06-11 Thread BALARUKESH SIVARAMAN
I missed out the condition that it should never be negative... Sorry for the comment... Thanks for correcting... -- 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

[algogeeks] Re: max sum

2010-06-11 Thread BALARUKESH
I hope using a backtracking solution suits the problem well... maxsum( int arr[] , int n,int i,int sum, int last) { if(in) { int s1= 0,s2= 0,s3; if(last ==i-1) { s1=maxsum(arr,n,i+2,sum,last); } else { s2= maxsum(arr,n,i+1,sum+arr[i],i);

[algogeeks] Re: Common elements in 2 circular linked lists

2010-06-11 Thread BALARUKESH
I hope u can do better... try this.. use a hash table and try inserting all elements of 1st list and then insert the elements of second list. if u find an element already existing when u insert from second list then add it to a new list. the new list has the common elements... -- You received

[algogeeks] Re: infix

2010-06-10 Thread BALARUKESH
The increment and decrement method wont work correctly for all cases Ex:- ))a+b(( This is not a well formed parenthesis... But satisfies the algorithm. The better way is to use a stack... When u find a ' ( ' push it into the stack and when u find a ' )' pop off the top element. Finally the