|
||
Title: dynamic-set operation Post by nks on Jan 28th, 2009, 1:19am Question from book of H.Cormen. The dynamic-set operation UNION takes two disjoint sets S1 and S2 as input, and it returns a set S = S1 U S2 consisting of all the elements of S1 and S2. The sets S1 and S2 are usually destroyed by the operation. How to support UNION in O(1) time using a suitable list data structure ? Can anybody explain the question? |
||
Title: Re: dynamic-set operation Post by towr on Jan 28th, 2009, 1:34am on 01/28/09 at 01:19:25, nks wrote:
[hide]If they're disjoint, you can just join the two lists. L1.last()->next=L2.first(); It may be inconvenient for other operations, though.[/hide] |
||
Title: Re: dynamic-set operation Post by nks on Jan 28th, 2009, 2:06am Is it like how to disjoint the union set after destroying the S1 and S2 ? |
||
Title: Re: dynamic-set operation Post by towr on Jan 28th, 2009, 2:51am on 01/28/09 at 02:06:24, nks wrote:
|
||
Title: Re: dynamic-set operation Post by Grimbal on Jan 28th, 2009, 6:33am I think the question is simply: how to compute the union of 2 sets. You are asked to describe what list structure is suitable for the task. You are not requested to preserve the original lists, which means you can take break apart the original lists and reassemble the union from that. |
||
Title: Re: dynamic-set operation Post by nks on Jan 28th, 2009, 10:52pm I think question is making union of 2 sets using these sets so original can be destroyed . So once union is done it should not depend on original set s1 and s2. |
||
Powered by YaBB 1 Gold - SP 1.4! Forum software copyright © 2000-2004 Yet another Bulletin Board |