Re: [algogeeks] Finding intersection of 2 linked lists

2012-07-04 Thread Amit Chauhan
If both the linked list are ordered one then you can solve this problem in
linear time and with constant space.



On Wed, Jul 4, 2012 at 10:41 PM, Abhi  wrote:

> Any efficient algorithm to find intersection of two linked lists.Example:
> Linked List 1)  1 -> 2 -> 3 -> 4 -> 5 -> 6
> Linked List 2)  3 -> 4 -> 5
>
> Intersection 4 -> 5 -> 6
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/-8_lnGA-ZhgJ.
> 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] Link list Q

2011-12-01 Thread Amit Chauhan
Option (c) is correct. detects the loop in singly linked list

**


On Thu, Dec 1, 2011 at 1:42 PM, Vijay Khandar wrote:

> What does the following program do on the singly linked list?
>
> p=head;
> q=head->next;
> while(p!=null && q!null)
> {
> if(p==q)
> {
> exit(0)
> }
> p=p->next;
> q=(q->next)?(q->next->next):q->next;
> }
>
> a)traverse the entire singly linked list
> b)detects the duplicate nodes
> c)detects the loop in singly linked list
> d)detects the duplicate nodes at alternate places
>
> plz explain anyone with correct option..
>
> --
> 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] Re: finding whether sum of two numbers of array is equal to given number or not ? plz tell why my this is not working for x=10,11,13 values

2011-06-11 Thread Amit Chauhan
Hi,

For x = 10,11,12,13 it is going in infinite loop.

Your recursive call for binary_search function is going in infinite loop. So
please look in to the logic for binary search function.

And one more thing once you sort the array and after this you can search the
pair  in linear time { for searching the element}.


***Thanks and Regards
*
*Amit K Chauhan*



*

   There is always, always, always something to be thankful for !!

*


On Thu, Jun 9, 2011 at 10:57 AM, D.N.Vishwakarma@IITR wrote:

> we have to find in O(nlgn)
>
>
> On Thu, Jun 9, 2011 at 10:55 AM, D.N.Vishwakarma@IITR 
> wrote:
>
>> #include
>> using namespace std;
>> void merge(int A[],int p,int q,int r)
>> {
>> int n1=q-p+1;int n2=r-q;
>> int L[n1];
>> int R[n2];
>> for(int i=0;i> L[i]=A[p+i];
>> for(int j=0;j> R[j]=A[q+j+1];
>> int i=0,j=0,k;
>>
>> for(k=p;k> {
>> if((L[i]<=R[j])&&i> {A[k]=L[i];i++;}
>> else
>> {A[k]=R[j];j++;}
>> }
>>
>> for(;i> {A[k]=L[i];k++;}
>>
>> for(;j> {A[k]=R[j];k++;}
>>
>> }
>>
>> //Merge Sort
>> void merge_sort(int A[],int p,int r)
>> {
>> int q;
>> if(p> {
>> q=(p+r)/2;
>> merge_sort(A,p,q);
>> merge_sort(A,q+1,r);
>> merge(A,p,q,r);
>> }
>> }
>>
>> //binary search
>> int binary_search(int A[],int left,int right,int val)
>> {
>> int result;
>> int mid=(left+right)/2;
>> if((right-left)==1&&val!=A[mid])
>> result=-1;
>> if(val> result=binary_search(A,left,mid-1,val);
>> else if(val>A[mid])
>> result=binary_search(A,mid+1,right,val);
>> else
>> result= mid;
>> return result;
>> }
>>
>>
>> //main function
>> int main()
>> {
>> int A[]={3,2,4,6,5,7};
>> merge_sort(A,0,5);
>> for(int i=0;i<6;i++)
>> cout<> cout<> int x;
>> cout<<"Enter value of x(=sum of two items in array)"<> cin>>x;
>> int pos;int flag=0;int i;
>> for( i=0;i<6;i++)
>> {
>> if((x-A[i])>0&&(pos=binary_search(A,i+1,5,x-A[i]))>=0)
>> {flag=1;break;}
>> }
>> if(flag)
>> {
>> cout<<"There are  two whose sum is equal to given number"<> cout<<"Those numbers are "<> }
>> else
>> cout<<"There are no such two numbers"<>
>> return 0;
>> }
>>
>>
>> --
>> **With Regards
>> Deoki Nandan Vishwakarma
>> IITR MCA
>> *
>> *
>>
>>
>
>
> --
> **With Regards
> Deoki Nandan Vishwakarma
> IITR MCA
> *
> *
>
>  --
> 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] Re: plz tell what is wrong in my this code... This code is for finding whether there are two numbers in array whose sum is exactly equal to given value x or not ... program is given as

2011-06-11 Thread Amit Chauhan
Hi,

Your recursive call for binary_search function is going in infinite loop. So
please look in to the logic for binary search function.

And one more thing once you sort the array and after this you can search the
pair  in linear time { for searching the element}.


*Thanks and Regards
*
*Amit K Chauhan*



*

   There is always, always, always something to be thankful for !!

*


On Thu, Jun 9, 2011 at 8:57 AM, D.N.Vishwakarma@IITR wrote:

> we have to find solution in O(nlgn)
>
> On Thu, Jun 9, 2011 at 8:22 AM, D.N.Vishwakarma@IITR wrote:
>
>> thanx in advance
>>
>> --
>> **With Regards
>> Deoki Nandan Vishwakarma
>> IITR MCA
>> *
>> *
>>
>
>
>
> --
> **With Regards
> Deoki Nandan Vishwakarma
> IITR MCA
> *
> *
>
>  --
> 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.



[algogeeks] Re: minimum difference.

2009-09-02 Thread Amit Chauhan
It won't work for following case

If suppose array contains the following integers
10 5 1 15 9
then according to you answer would be diff = |1-5| = 4
but correct answer is diff = |9-10| = 1

Thanks and Regards

Amit Chauhan
http://web.iiit.ac.in/~chauhan
Mobile : +91-9966347645

Y! IM   :  amitc_...@yahoo.co.in
GTalk  : amitchauhan@gmail.com



  There is always, always, always something to be thankful for !!

Sent from Hyderabad, AP, India
Ogden Nash <http://www.brainyquote.com/quotes/authors/o/ogden_nash.html>  -
"The trouble with a kitten is that when it grows up, it's always a cat."

On Wed, Sep 2, 2009 at 2:57 PM, Varun S V  wrote:

> Since we difference between two minumum elements should suffice, how about
> finding the min and second minimum element in the array in single scan and
> returning their difference. This should take not more than O(N) time.
>
> Regards,
> -Varun.
>
>
> On Wed, Sep 2, 2009 at 12:09 AM, Shishir Mittal <1987.shis...@gmail.com>wrote:
>
>> Sort the array and find the minimum of difference of adjacent values of
>> the sorted array.
>> Time Complexity : O(nlogn), Space Complexity : O(1)
>>
>> On Tue, Sep 1, 2009 at 6:35 PM, ankur aggarwal 
>> wrote:
>>
>>> given  a array of length n. find  2 number such that their differnce is
>>> minimum.
>>>
>>>
>>>
>>>
>>>
>>
>>
>> --
>> Shishir Mittal
>> Ph: +91 9936 180 121
>>
>>
>>
>>
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[algogeeks] Re: Check divisibility by 3

2009-08-17 Thread Amit Chauhan

#include

int main() {
int num,tmp=1;
printf("Enter the number \n");
scanf("%d",&num);

while(num>9) {
while(num>tmp)
tmp=tmp<<1;
tmp>>1;
num=num-tmp;
tmp=1;
}
if(num==9 || num==6 || num==3)
printf("\nNumber divisible by 3");
else
printf("\nNumber is not divisible by 3");
return 0;
}

On Aug 14, 12:45 pm, richa gupta  wrote:
> can we check the divisibility of a given number by 3 withoutusing
> operators like '/' or '%'.
> I want the efficient solution to this problem ..
>
> can someone help ??
> --
> Richa Gupta
> (IT-BHU,India)

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---