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)
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
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
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
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
#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