Wednesday, April 23, 2014

Venn diagrams and SQL Unions, Intersections of Sets


The coolest & applicable part of the Data Structures course. Enjoy.



Application in code:

To calculate the union, intersection, or set difference of two sets non-destructively (without modifying either set),
the caller must copy one set before calling the appropriate bulk operation. The following are the resulting idioms.


"FindDups" program. Suppose you want to know which words in the argument list occur only once and which occur more than once, but you do not want any duplicates printed out repeatedly. This effect can be achieved by generating two sets — one containing every word in the argument list and the other containing only the duplicates. The words that occur only once are the set difference of these two sets, which we know how to compute. Here's how the resulting program looks.

Produce a third List consisting of the second list appended to the first.


Pretty cool !


No comments:

Post a Comment