Q10.
array a[]={19 16 18 3 50 70 12 11 14}
array b[];
sum required=30
3 11 12 14 16 18 19 50 70 //sort
0 1 2 3 4 5 6 7 8 //index
l r
count=0,i=0;
while(l<r)
{
if(a[l]+a[r])>sum
r--;
elseif(a[l]+a[r])<sum
l++;
else
{
count++;
b[i++]=a[l];
b[i++]=a[r];
}
}
now b(1,2) carries sum=30 1st time
b(3,4) carries sum=30 2nd time...and so on
if b[] is empty then sum doesnt exist.
On Thu, Jul 7, 2011 at 9:51 AM, Navneet Gupta <[email protected]> wrote:
> Anyone for Q10, i wonder if it can really be solved in O(n). Very
> obvious O(nlogn) is what I know
>
> On Thu, Jul 7, 2011 at 1:25 AM, KK <[email protected]> wrote:
> > for Q5 change the expr into postfix and then build expression tree...
> > but is expression tree same as parse tree??
> > correct me if i m wrong!!
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> [email protected].
> > For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
>
>
> --
> Regards,
> Navneet
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.