Taking an intersection of a list of sets

Say that I currently have a list {A, B, C, D, E} and that I want to take the intersection of A n B n C n D n E

How can I do this? I can't think of a way to extract the sets from the list in a way that would allow me to take an overall intersection.


[EDIT]

It seems I was unclear about what I needed and for that I apologise. Though this specific example only has five sets, I need a method that works for any number of sets. This was my fault for not making it explicitly clear. 

Further, I believe the intersection function will not work, since if I don't know the length of the list of sets, I cannot retrieve them individually, and hence I cannot put them into the intersection function, even though it can handle multiple sets. 

Apologies to everyone who has taken the time to submit an answer to the specific case in the question. 

  Discussion posts and replies are publicly visible

Parents
  • Think of a data structure, say a tree.

    Convert your set A into a tree then do a scan of all other branches for common element like in the implementation of a sort algorithm.

    Simply, loop through every element of only one of the for sets. Reason; the mathematical law of set intersect states that every intersect element amongst nth number of sets exist in each of the sets.

    So, you have a nexted loop.

    For each element in set A

       Loop through all other elements of the other sets

       B, C & D for existence.

       If found in all the sets, then it's an intersect element.

    Next

    Your problem is centered around mathematics and algorithm, try to read up.

    Don't forget to upvote. Feel free to follow me. If you have any questions feel free to contact me as well.

    If you need guidance on your project, I am available as well.

    Good luck!

Reply
  • Think of a data structure, say a tree.

    Convert your set A into a tree then do a scan of all other branches for common element like in the implementation of a sort algorithm.

    Simply, loop through every element of only one of the for sets. Reason; the mathematical law of set intersect states that every intersect element amongst nth number of sets exist in each of the sets.

    So, you have a nexted loop.

    For each element in set A

       Loop through all other elements of the other sets

       B, C & D for existence.

       If found in all the sets, then it's an intersect element.

    Next

    Your problem is centered around mathematics and algorithm, try to read up.

    Don't forget to upvote. Feel free to follow me. If you have any questions feel free to contact me as well.

    If you need guidance on your project, I am available as well.

    Good luck!

Children
No Data