Question

In: Computer Science

C++ Given two finite sets, list all elements in the Cartesian product of these two sets.

C++

Given two finite sets, list all elements in the Cartesian product of these two sets.

Solutions

Expert Solution

Solution:

#include <iostream>

#include <vector>

#include <utility>

using namespace std;

int main() {

//finite sets

int M[3]= {1,2,3};

int N[3] = {4,5,6};

vector<pair<int,int>> Arr;

//iteration for cartesian product elements

for (int i = 0; i < sizeof(M)/sizeof(M[0]); i++)

{

for (int j = 0; j < sizeof(N)/sizeof(N[1]); j++)

{

Arr.push_back(make_pair(M[i],N[j]));

}

}

//to print elements of cartesian product

for (int i = 0; i < Arr.size(); i++)

{

cout <<"{"<< Arr[i].first << "," << Arr[i].second << "}"<<endl;

}

}

Thank you, Have a great day:-)


Related Solutions

What are good textbooks to cover these topics? Sets: sets and their elements, finite and infinite...
What are good textbooks to cover these topics? Sets: sets and their elements, finite and infinite sets, operations on sets (unions, intersections and complements), relations between sets(inclusion, equivalence), non equivalent infinite sets, cardinal numbers. Binary Operations: basic definitions, associativity commutativity, neutral elements, inverse elements, groups. Functions: introduction, Cartesian products, functions as subsets of Cartesian products, graphs, composition of functions, injective, bijective and surjective functions, invertible functions, arithmetic operations on real functions, groups of functions. Plane isometries: definition, reflections, translations and...
The intersection (∩) of two sets (s1, s2) is the set of all elements that are...
The intersection (∩) of two sets (s1, s2) is the set of all elements that are in s1 and are also in s2. Write a function (intersect) that takes two lists as input (you can assume they have no duplicate elements), and returns the intersection of those two sets (as a list) without using the in operator or any built-in functions, except for range() and len(). Write some code to test your function, as well. Note: Do not use the...
1. (14) List the elements for each of the following sets:
  1. (14) List the elements for each of the following sets: (1) P({a, b, c})                                                         (Note: P refers to power set) (2)   P{a, b}) - P({a, c}) (3)   P(Æ) (4) {x Î ℕ: (x £ 7 Ù x ³ 7}                        (Note: ℕ is the set of nonnegative integers) (5)   {x Î ℕ: $y Î ℕ (y < 10 Ù (y + 2 = x))}            (6)    {x Î ℕ: $y Î ℕ ($z Î ℕ ((x = y +...
In Python, Given a list of numbers, return a list where all adjacent == elements have...
In Python, Given a list of numbers, return a list where all adjacent == elements have been reduced to a single element, so [1,2,2,3,3,2,2,4] returns [1,2,3,2,4]. You may create a new list or modify the passed in list (set function does not work in this case).
write a recursive method that returns the product of all elements in java linked list
write a recursive method that returns the product of all elements in java linked list
Consider any two finite sets A and B. Prove that |A×B|=|A||B|
Consider any two finite sets A and B. Prove that |A×B|=|A||B|
Given two sets S and T, the direct product of S and T is the set...
Given two sets S and T, the direct product of S and T is the set of ordered pairs S × T = {(s, t)|s ∈ S, t ∈ T}.Let V, W be two vector spaces over F. (a) Prove that V × W is a vector space over F under componentwise addition and scalar multiplication (i.e. if (v1, w1),(v2, w2) ∈ V × W, then (v1, w1) + (v2, w2) = (v1+w1, v2+w2) and a(v, w) = (av, aw)...
Let A be a collection of sets, then We defined A’ = Union of all elements...
Let A be a collection of sets, then We defined A’ = Union of all elements of A. Definition: If A = NOT the union of C and D , where C and D are non empty sub-collection, such that C’ intersect D’ = empty Then A is coherent. Prove: if A is coherent then A’ is connected (i.e A’ is not the union of two separated sets in standard topology)
Unless otherwise noted, all sets in this module are finite. Prove the following statements... 1. If...
Unless otherwise noted, all sets in this module are finite. Prove the following statements... 1. If A and B are sets then (a) |A ∪ B| = |A| + |B| − |A ∩ B| and (b) |A × B| = |A||B|. 2. If the function f : A→B is (a) injective then |A| ≤ |B|. (b) surjective then |A| ≥ |B|. 3. For each part below, there is a function f : R→R that is (a) injective and surjective. (b)...
A={1,3,4},B={2,3} Check ALL of the Cartesian products to which the following elements belong: (1,1) A. A×A...
A={1,3,4},B={2,3} Check ALL of the Cartesian products to which the following elements belong: (1,1) A. A×A B. A×B C. B×B D. B×A (3,3) A. B×B B. A×A C. B×A D. A×B (3,1) A. B×B B. B×A C. A×B D. A×A (1,2) A. A×A B. B×A C. A×B D. B×B
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT