[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Arun Subramanian
But If there is no loop in the original list then this code will give incorrect result. the algo should hav been somethin like if loopispresent return the looping node else return NULL --~--~-~--~~~---~--~~ You received this message becaus

[algogeeks] Hi All

2007-04-04 Thread maverick
I'm Vikram, a new member to this group. --~--~-~--~~~---~--~~ 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 e

[algogeeks] Re: Sum of subsets

2007-04-04 Thread pramod
Dor, Yes, you are right and your method works. On Apr 3, 1:05 pm, "dor" <[EMAIL PROTECTED]> wrote: > Yes, you do know S. The problem statements says find the *subset* of S > that sums to k, if any. > Not knowing S does not make any sense anyway. S and k are an instance > of SUBSET-SUM. > > On A

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Dhruva Sagar
:-S On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote: > > This is the right one, with the correction. temp1 -> temp. > By the way aakash, that point was a good one. > > On 4/4/07, Dhruva Sagar < [EMAIL PROTECTED]> wrote: > > > > Based on aakash's explanation there is another solution (similar to

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Dhruva Sagar
This is the right one, with the correction. temp1 -> temp. By the way aakash, that point was a good one. On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote: > > Based on aakash's explanation there is another solution (similar to point > no 2.) > > Traverse the link list and keep nulling the pointer

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Dhruva Sagar
Based on aakash's explanation there is another solution (similar to point no 2.) Traverse the link list and keep nulling the pointers in the link list. When you reach the end, the last node you reach to is the node where the looping is occurring. Node*findLoopingNode(Node*start) { Node*temp=sta

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread aakash mandhar
There are many efficient ways to do this. I am listing them out. 1) Use two pointers. One advancing one node at a time and the other advancing 2 nodes at a time. So that the relative speed between them is always one node. If the first and second pointer coincide then there is a loop. 2) Destructi

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Dhruva Sagar
An alternate solution may be something like this: You have two loops. one inside another. node*temp1=start,*temp2=start; node*loopingNode=null; while(temp1) { while(temp2) { if(temp1->next=temp2->next) { loopingNode=temp1->next; break; } temp2=temp2->n

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Pradeep Juneja
That's one solutionbut I am having memory constraintso need some optimized algo On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote: > > Yes and hence i mentioned that it would be better if you have a unique key > such as an index as a property of the node itself. For example the info part >

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Dhruva Sagar
Yes and hence i mentioned that it would be better if you have a unique key such as an index as a property of the node itself. For example the info part of the node may have a index. Then you could add that unique key to an array and check and compare that to determine if a node is being traversed

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Pradeep Juneja
It will consume lot of memory (varying on the length of link list). On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote: > > I guess you can keep an array of node pointers where you could add the > addresses of the nodes as you traverse through the link list. And you could > loop through the arr

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Dhruva Sagar
I guess you can keep an array of node pointers where you could add the addresses of the nodes as you traverse through the link list. And you could loop through the array to match the current node to the traversed nodes. If there is a match it means that you are encountering that node again and henc

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Pradeep Juneja
Which data structure will be used to keep track of unique identifier? We are not allowed to modify the struct node of linked list On 4/4/07, Dhruva Sagar <[EMAIL PROTECTED]> wrote: > > It would be easy to do in case there is a unique identifier for each node. > Simply traverse through the link li

[algogeeks] Re: Loop in a linked list

2007-04-04 Thread Dhruva Sagar
It would be easy to do in case there is a unique identifier for each node. Simply traverse through the link list and when you encounter a node twice it means that the link list is looping at that node. On 4/4/07, Pradeep Juneja <[EMAIL PROTECTED]> wrote: > > > > How can we know at what node, list

[algogeeks] Loop in a linked list

2007-04-04 Thread Pradeep Juneja
How can we know at what node, list has the loop ? i.e A>B->*C*--->D-->E--F- | | - - -| --~--~-~--~~~---~--~~ You receive