Re: [algogeeks] Re: Interview Question

2011-07-02 Thread Pranav Agarwal
I think that the above algo will fail for the following two arrays:
a={2,2,3,3}
b={4,4,1,1}

sum(a)=sum(b);
a^b=0;
len(a)=len(b);

Correct me if i am wrong!

Pranav

On Sun, Jul 3, 2011 at 7:43 AM, varun pahwa wrote:

> @aditya. xor all elements mean that. take xor of each element of 1st array
> store in a variable that take xor of variable and each element of the second
> array if all elements are common then the variable will be 0 some where.
> var = a[0];
> for(i = 1; i < sizeof(a)/sizeof(a[0]); i++)
> var = var ^ a[i];
> for(i = 0; i < sizeof(b)/sizeof(b[0]); i++)
> var = var ^ b[i];
>
>
>
> On Sat, Jul 2, 2011 at 2:19 PM, aditya kumar  > wrote:
>
>> @mohit..:i dint get the logic behind XOR plz explain ..nd ya i dont think
>> dat you can find second largest in less than O(n).
>>
>>
>> On Sun, Jul 3, 2011 at 2:43 AM, mohit mittal wrote:
>>
>>> Dont think that the corresponding elements should be same.
>>> XOR Should do it anyway.
>>>
>>> Btw other question "How would you find the second largest element in an
>>> array using minimum no of comparisons?Any thing better than O(n)."?
>>>
>>>
>>> On Sun, Jul 3, 2011 at 2:41 AM, aditya kumar <
>>> aditya.kumar130...@gmail.com> wrote:
>>>
 xor will only result if corresponding elements are same . what if in
 both the array set of integers are same but they arnt corresponding to each
 other ??


 On Sun, Jul 3, 2011 at 2:37 AM, Dumanshu  wrote:

> xor all the elements of both arrays ==0
> sum of 1st array == sum of 2nd array
> no. of elements in 1st == no. of elements in 2nd
> if the above conditions are met, they have the same set.
> m i missin sth?
> On Jul 3, 1:23 am, mittal  wrote:
> > Given two arrays of numbers, find if each of the two arrays have the
> same
> > set of ntegers ? Suggest an algo which can run faster than NlogN
> without
> > extra space?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
  --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>
>>>
>>> --
>>> Mohit Mittal
>>> 4th year , Computer Engineering
>>> Student-Coordinator , DTU WebTeam
>>> Delhi Technological University
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Varun Pahwa
> B.Tech (IT)
> 7th Sem.
> Indian Institute of Information Technology Allahabad.
> Ph : 09793899112 ,08011820777
> Official Email :: rit2008...@iiita.ac.in
> Another Email :: varunpahwa.ii...@gmail.com
>
> People who fail to plan are those who plan to fail.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] maximize result

2010-12-18 Thread Pranav Agarwal
I am not sure about this but a quick thought on the question:

If we give plus a higher precedence than multiplication, then we get a
higher result.
For eg:

3 + 6 * 7 + 3 * 2

BODMAS => 51

But giving plus a higher precedence will imply 180

Unable to think of any counter examples. Give if any, otherwise a simple
greedy approach is to parenthesize all the plus together and then
parenthesize through the multiplication.

For the above example:  (3+6)*(7+3)*2

Pranav

On Sat, Dec 18, 2010 at 11:15 PM, snehal jain  wrote:

> Given an expression E of n numbers with *, + operations and no
> precedence among the operators, identify the set of parenthesis which
> maximize the results for E.
>
> --
> 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 options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.