Sets. Cartesian Product.

  • Difficulty: easy

Sets#

The Cartesian Product algorithm uses sets to calculate the sets of multiple elements. When working with sets, there are some basic terms we need to understand first.

In mathematics, a set is a collection of distinct objects, considered as an object in its own right. For example numbers 2, 1, 0 and 14 may form a set of numbers {2, 1, 0, 14}. Strings 'apple', 'banana' and 'grape' may form a set of strings/fruits {'apple', 'banana', 'grape'}. We can use arrays in JavaScript to create sets.

The objects that form a set are called set elements.

Cartesian Product#

A cartesian product is a mathematical operation that returns a set (or product set or product) from multiple sets. For two sets A and B the product set A×B will consist of all possible ordered pairs (a,b) where a is an element of A set and b is an element of B.

This lesson preview is part of the JavaScript Algorithms course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

Unlock This Course

Get unlimited access to JavaScript Algorithms, plus 0+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course JavaScript Algorithms