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)

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

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 s

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

[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 : a

[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