[algogeeks] Most compatible people

2012-07-05 Thread enchantress


Given a list of people and music bands they like, two people are compatible 
if they have at least 2 bands in common. The compatibility of two people is 
directly proportional to the number of bands they like in common.

Find the two most compatible people that is having maximum number of bands 
in common.

Number of people and bands can be as large as 10k.


-- 
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/-/jTyHI3QeB6kJ.
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: simple FILE reading problem.

2012-07-05 Thread Zyro
@Navin : Read a line .. store it in a string .. then extract numbers frm 
it.. It will be more faster i think.. :)
On Wednesday, 4 July 2012 22:44:04 UTC+5:30, Navin Kumar wrote: 
>
> Suppose a file.txt contains : 50 40 30 # # 5 # 10 # #
>
> i want to fetch only integers. How should i fetch it. I tried with fgetc 
> and fscanf but it was too complicated.
>
> My approach: fetched one word at a time and put it into separate string 
> and then i converted that string to integer(if each character of that 
> string was between '0' to '9').
>
> Is there any simple way to do this. 
>  
>

-- 
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/-/sR5uBPpS2HQJ.
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: Write a C program to reconstruct a BST from a given array of preorder traversal.

2012-07-05 Thread Zyro
??

-- 
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/-/HQ_TvoKSLNgJ.
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: Write a C program to reconstruct a BST from a given array of preorder traversal.

2012-07-05 Thread Zyro


> @Navin : Why r u sorting the array .. BST can be made using the preorder 
> traversal if null nodes are well defined in the given traversal.. Right??
>

-- 
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/-/VCvNv0yZtxMJ.
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: Finding intersection of 2 linked lists

2012-07-05 Thread himanshu tyagi
here is a recursive method. First sort the two list and use the following 
algo.
initial value of third parameter is NULL.
struct node *sortedIntersect(struct node *a, struct node *b, 
  struct node *result)
{
  /* base case */
  if(a == NULL || b == NULL)
  {
return NULL;
  }  
   
  /* If both lists are non-empty */
 
  /* advance the smaller list and call recursively */
  if(a->data < b->data)
  {
return sortedIntersect(a->next, b, result);
  }
  else if(a->data > b->data)
  {
return sortedIntersect(a, b->next, result);
  }  
  else if(a->data == b->data)
  {
/* If same data is found then allocate memory */
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->data = a->data;
  
/* If the first node is being added to resultant list */
if(result == NULL)
{
  result = temp;
}

/* Else change the next of result and move result to next */
else
{ 
  result->next = temp;
  result = temp;
}
 
/* advance both lists and call recursively */
result->next = sortedIntersect(a->next, b->next, result);
  }
  
  return result;


On Wednesday, 4 July 2012 22:41:57 UTC+5:30, 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/-/i7XgIpbhWhIJ.
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: Finding intersection of 2 linked lists

2012-07-05 Thread Navin Gupta
Use two pointers to traverse both the linked-lists.
while(List1 && List2) 
{
   if(List1->data == List2->data ), then add it to the 
Intersect_List.
   if(List1->data < List2->data )  then move List1 pointer i.e. 
List1=List1->next;
   else move List2 pointer i.e. List2=List2->next;
}
return the intersectList.

--
Navin Kumar Gupta
Final Year,B.Tech(Hons.)
Computer Science & Engg.
National Institute of Technology,Jamshedpur
Mobile - (+91)8285303045

-- 
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/-/hk3K2Z0WQ0kJ.
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: Finding intersection of 2 linked lists

2012-07-05 Thread himanshu tyagi
here is an recursive method the two linked list have to be in sorted 
order.

struct node *sortedIntersect(struct node *a, struct node *b, 
  struct node *result)
{
  /* base case */
  if(a == NULL || b == NULL)
  {
return NULL;
  }  
   
  /* If both lists are non-empty */
 
  /* advance the smaller list and call recursively */
  if(a->data < b->data)
  {
return sortedIntersect(a->next, b, result);
  }
  else if(a->data > b->data)
  {
return sortedIntersect(a, b->next, result);
  }  
  else if(a->data == b->data)
  {
/* If same data is found then allocate memory */
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->data = a->data;
  
/* If the first node is being added to resultant list */
if(result == NULL)
{
  result = temp;
}

/* Else change the next of result and move result to next */
else
{ 
  result->next = temp;
  result = temp;
}
 
/* advance both lists and call recursively */
result->next = sortedIntersect(a->next, b->next, result);
  }
  
  return result;


On Wednesday, 4 July 2012 22:41:57 UTC+5:30, 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/-/m7IddmbTkMEJ.
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] MS Design Ques

2012-07-05 Thread payal gupta
thnx...4 d rply..

Regards,
PAYAL GUPTA,
NIT-B.

On Fri, Jul 6, 2012 at 12:43 AM, Anshu Mishra wrote:

> First define all the basic operation you can apply on two numbers.
>
> Binary operation : +, -, *, /, %, optional(&(and), |(or), ^(xor))
> Unary operation : !, ~, -
> Comparison : <, > ==, !=
>
> Define all these operation.
>
> Most simplest one can be,
> class BIG_INT {
>private string val;
>//Define constructor
>private BIG_INT(){}
>public BIG_INT(int x) {
>this.val = x.toString();
>}
>public BIG_INT(long x) {
>this.val = x.toString();
>}
>public BIG_INT(string x) {
>this.val = x;
>}
>public BIG_INT add(BIG_INT x);
>public BIG_INT add(int x);
>public BIG_INT add(long x);
>
>   similarly write methods for other operation also;
>
>   }
>
> If this question asked for only design testing purpose only all method
> declaration will be sufficient.
>
> --
> Anshuman Mishra | Software Development Engineer | Amazon
>
>
>  --
> 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] MS Design Ques

2012-07-05 Thread Anshu Mishra
First define all the basic operation you can apply on two numbers.

Binary operation : +, -, *, /, %, optional(&(and), |(or), ^(xor))
Unary operation : !, ~, -
Comparison : <, > ==, !=

Define all these operation.

Most simplest one can be,
class BIG_INT {
   private string val;
   //Define constructor
   private BIG_INT(){}
   public BIG_INT(int x) {
   this.val = x.toString();
   }
   public BIG_INT(long x) {
   this.val = x.toString();
   }
   public BIG_INT(string x) {
   this.val = x;
   }
   public BIG_INT add(BIG_INT x);
   public BIG_INT add(int x);
   public BIG_INT add(long x);

  similarly write methods for other operation also;

  }

If this question asked for only design testing purpose only all method
declaration will be sufficient.

-- 
Anshuman Mishra | Software Development Engineer | Amazon

-- 
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] Finding intersection of 2 linked lists

2012-07-05 Thread Nishant Pandey
both the distance means distance between the two linked list some thing
like this :



struct node *temp1,*temp2;
temp1 = head1;
temp2 = head2;

int l1 = get_dist(head1);
int l2 = get_dist(head2);

int ds = abs(l1-l2);
if( l1 > l2 )
{

   for(int i=0;inext)temp1 = temp1->next;
  }
  // here distance of both the list is equal .
  // now you may traverse like this
   while(temp1 && temp2)
   {
   if(temp1 == temp2 )
 // intersection point
  else
   temp1 = temp1->next;
   temp2 = temp2->next;
  // move both one one step a time will come both will meet the
intersection point
  // i hope the point is clear if not let me knw i will send u
the whole code .
   }
}
else
{
   // similary for (l1wrote:

> @nishant, you wrote "until both the distance becomes equal".Which
> distances ? Could you please elaborate ?
>
>
> On Thu, Jul 5, 2012 at 12:52 PM, Ashish Goel  wrote:
>
>> struct node* intersection( struct node *pL1, struct node* pL2)
>> {
>>if ((!pL1) || (!pl2)) return NULL;
>>struct node * pL3 = NULL;
>>struct node* pL3Tail = NULL;
>>while(pL1)&&(pL2) {
>> if (pL1->data< pL2->data) pL1=pL1->next;
>> else if  (pL1->data > pL2->data) pL2=pL2->next;
>> else {
>>struct node *pNew = (struct node*)malloc(sizeof(struct node));
>>if !pNew return NULL; //scary
>>pNew->data = pL1->data; pNew->next = NULL;
>>if ( !pL3) pL3= pNew;
>>else pL3Tail->next = pNew;
>>pL3Tail = pNew;
>>}
>>return pL3;
>> }
>>
>>
>>
>>
>> }
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>> 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.
>>
>
>
>
> --
> Abhishek Sharma
> Under-Graduate Student,
> PEC University of Technology
>
>  --
> 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] Finding intersection of 2 linked lists

2012-07-05 Thread adarsh kumar
Hope the following will be of help:
http://www.geeksforgeeks.org/archives/18615

regds.

On Thu, Jul 5, 2012 at 4:32 PM, Abhishek Sharma wrote:

> @nishant, you wrote "until both the distance becomes equal".Which
> distances ? Could you please elaborate ?
>
>
> On Thu, Jul 5, 2012 at 12:52 PM, Ashish Goel  wrote:
>
>> struct node* intersection( struct node *pL1, struct node* pL2)
>> {
>>if ((!pL1) || (!pl2)) return NULL;
>>struct node * pL3 = NULL;
>>struct node* pL3Tail = NULL;
>>while(pL1)&&(pL2) {
>> if (pL1->data< pL2->data) pL1=pL1->next;
>> else if  (pL1->data > pL2->data) pL2=pL2->next;
>> else {
>>struct node *pNew = (struct node*)malloc(sizeof(struct node));
>>if !pNew return NULL; //scary
>>pNew->data = pL1->data; pNew->next = NULL;
>>if ( !pL3) pL3= pNew;
>>else pL3Tail->next = pNew;
>>pL3Tail = pNew;
>>}
>>return pL3;
>> }
>>
>>
>>
>>
>> }
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>> 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.
>>
>
>
>
> --
> Abhishek Sharma
> Under-Graduate Student,
> PEC University of Technology
>
>  --
> 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] Finding intersection of 2 linked lists

2012-07-05 Thread Abhishek Sharma
@nishant, you wrote "until both the distance becomes equal".Which distances
? Could you please elaborate ?

On Thu, Jul 5, 2012 at 12:52 PM, Ashish Goel  wrote:

> struct node* intersection( struct node *pL1, struct node* pL2)
> {
>if ((!pL1) || (!pl2)) return NULL;
>struct node * pL3 = NULL;
>struct node* pL3Tail = NULL;
>while(pL1)&&(pL2) {
> if (pL1->data< pL2->data) pL1=pL1->next;
> else if  (pL1->data > pL2->data) pL2=pL2->next;
> else {
>struct node *pNew = (struct node*)malloc(sizeof(struct node));
>if !pNew return NULL; //scary
>pNew->data = pL1->data; pNew->next = NULL;
>if ( !pL3) pL3= pNew;
>else pL3Tail->next = pNew;
>pL3Tail = pNew;
>}
>return pL3;
> }
>
>
>
>
> }
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
> 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.
>



-- 
Abhishek Sharma
Under-Graduate Student,
PEC University of Technology

-- 
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] Finding intersection of 2 linked lists

2012-07-05 Thread Ashish Goel
struct node* intersection( struct node *pL1, struct node* pL2)
{
   if ((!pL1) || (!pl2)) return NULL;
   struct node * pL3 = NULL;
   struct node* pL3Tail = NULL;
   while(pL1)&&(pL2) {
if (pL1->data< pL2->data) pL1=pL1->next;
else if  (pL1->data > pL2->data) pL2=pL2->next;
else {
   struct node *pNew = (struct node*)malloc(sizeof(struct node));
   if !pNew return NULL; //scary
   pNew->data = pL1->data; pNew->next = NULL;
   if ( !pL3) pL3= pNew;
   else pL3Tail->next = pNew;
   pL3Tail = pNew;
   }
   return pL3;
}




}
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


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.