The updated version of the Data Structures and Algorithms book that Luca and I wrote is flying out once more! We are really very happy to see how many people are downloading our book. In total (counting the previous release) the book has had nearly 16,000 downloads! Amazing.

If you haven’t already got a copy what are you waiting for?! Its free so you don’t have to reach into those empty pockets at this time of year.

Download the updated version of the Data Structures and Algorithms book here!

**Enjoy. Merry Christmas and a Happy New Year.**

Chapter 5: Sets; Intersection

While traversing the smallerset, there is no need to check if the smallerset contains the item. That is already known, or it would not have been found during the traversal. Syntax adjusted to use what this form allows.

1) algorithm Intersection(set1, set2)

2) Pre: set1, and set2 not 1 emptySet

3) intersection, smallerSet and largerSet are sets

3) Post: An intersection of set1, and set2 has been created

4) if set1.Count < set2.Count 5) smallerSet is set1 6) largerSet is set2 7) else 8) smallerSet is set2 9) largerSet is set1 10) end if 11) foreach item in smallerSet 12) if largerSet.Contains(item) 13) intersection.Add(item) 14) end if 15) end foreach 16) return intersection 17) end Intersection Alternative, 1) algorithm Intersection(set1, set2) 2) Pre: set1, and set2 not 1 emptySet 3) intersection is a set 3) Post: An intersection of set1, and set2 has been created 4) if set1.Count < set2.Count 5) foreach item in set1 6) if set2.Contains(item) 7) intersection.Add(item) 8) end if 9) end foreach 10) else 11) foreach item in set2 12) if set1.Contains(item) 13) intersection.Add(item) 14) end if 15) end foreach 16) end if 17) return intersection 18) end Intersection

Hi Phil,

I’ll recheck the algorithm when I have some time (which is hard to find these days).

Thanks.

Hi,

Where can you download the source code for the book?

Thanks

Hi newbie (although I has a feeling thats not your name ;-)),

All the source code for the book is the book itself. The examples given can be translated relatively friction free to your respective imperative language of choice. However, if you want an implementation then we have one on offer in the DSA CodePlex project – http://codeplex.com/dsa which is all done in C#.

HTH