Hello, I was working on something and thought that one part would suit as a nice exercise to share.
Problem:
Given a collection of sets with arbitrary sizes write a program to find the set resulting from their
intersection.
For example we have 3 sets: [ [0,4,5,2,1] , [1,3,6,2,4], [4,1,2,5,7,0] ] the resulting intersection would be: [1, 2, 4]
One possible application:
Set intersection is a fundamental operation in information retrieval applications such as search engines and database systems. For example in search indexing an inverted index stores a mapping from content, such as words or numbers, to its locations in a file, or in a document or a set of documents. Here is a very simple illustration:
Lets say we have 3 documents T0, T1, and T2 with the following texts:
T0 = "it is what it is",
T1 = "what is it" and
T2= "it is a banana"
The resulting
inverted index would be the following(Integers in the set notation brackets refer to the subscripts of the text symbols, T0, T1, and T2):
"a" : {2}
"banana" : {2}
"is" : {0, 1, 2}
"it": {0, 1, 2}
"what" : {0, 1}
A term search with the string: "what is it" would return the intersection of the sets related each keyword in the string:
{0,1} intersection {0,1,2} intersection {0,1,2} = {0,1} => documents T0 and T1 contain the words's we're looking for
I'll share my solution for the problem above in a few minutes, hope you enjoy it!