1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Katen [24]
3 years ago
8

Write an algorithm that prints out all the subsets of 3 elements of a set of n elements. The elements of the set are stored in a

list that is the input to the algorithm, (you may assume all elements in the list are distinct. The list can be an array). Algorithm: Print_3_Element_Subsets Input: List S of n distinct elements. Output: Print out all 3-element subsets of S. void Print_3_Element_Subsets (int n, const element_type S[])
Computers and Technology
1 answer:
Ksenya-84 [330]3 years ago
7 0

void Print_3_Element_Subsets(int n,const element_type S[])

{

if(n<3) // condition to check if list have less than 3 elements

{

print("No subset found");

}

for(int i =0; i < n ; i++)

{

for(int j =i+1; j < n ; j++)

{

for(int k =j+1; k < n ; k++)

{

print(S[i],S[j],S[k]);

}

}

}

}

C++ Implementation;

#include<cstdlib>

#include<time.h>

using namespace std;

int S1[5]= {1,2,3,4,5};

int n1 = 5;

int S2[2]={1,2};

int n2 = 2;

void Print_3_Element_Subsets(int n,const int S[])

{

if(n<3) // condition to check if list have less than 3 elements

{

printf("No subset found\n");

}

printf("3 Subsets are\n");

for(int i =0; i < n ; i++)

{

for(int j =i+1; j < n ; j++)

{

for(int k =j+1; k < n ; k++)

{

cout<<S[i]<<" "<<S[j]<<" "<<S[k]<<endl;

}

}

}

}

int main()

{

cout<<"Case 1"<<endl;

Print_3_Element_Subsets(n1,S1);

cout<<endl<<"Case 2"<<endl;

Print_3_Element_Subsets(n2,S2);

}

OUTPUT

Case 1

3 Subsets are

1 2 3

1 2 4

1 2 5

1 3 4

1 3 5

1 4 5

2 3 4

2 3 5

2 4 5

3 4 5

Case 2

No subset found

3 Subsets are

--------------------------------

Process exited after 0.0137 seconds with return value 0

Press any key to continue . . .

You might be interested in
What are the five types of alignment in Word?
Basile [38]
There are four types of alignment in word.
Left-aligned text
Right-aligned text
Center-aligned text
Justified text
6 0
4 years ago
Read 2 more answers
Arpenet was the computer created by the military true or false
Sphinxa [80]

True. It was a project that the pentagon was working on in the 60's

3 0
3 years ago
Disadvantages of using social network site GOAL SETTTING?
andriy [413]

Answer:

addiction, mental illness, misleading information, scams, cyberbullying

Explanation:

4 0
2 years ago
Suppose 8 people want to communicate with each other using public key encryption. The communication between any pair of them is
ludmilkaskok [199]

Answer:

The answer is "64"

Explanation:

There has been 1 Private Key 1 Public Key for every person. The private key is used for other app messages. All else uses the Public Key to encrypt messages with that user. Those keys are numerically related. Even if you have 5 users, you will be given 5 Personal keys and 5 Public keys.

  • All user will have a duplicate of other public keys, which indicates (n*n-1) copies of n public keys on different systems to make sure shared contact between all users, plus n private keys.
  • The unique key count is 2n, with n^2 distributed private and public keys on different systems.
  • 8 people,  where 8 is a number, that is equal to n so, n^2 = 8^2 =8 \times 8 = 64
5 0
3 years ago
__________ is a term that refers to the means of delivering a key to two parties that wish to exchange data without allowing oth
8_murik_8 [283]

Answer: email

Explanation:

7 0
4 years ago
Other questions:
  • Perform online research and learn about the elements of a presentation program interface not discussed in the lesson. Write a sh
    9·1 answer
  • In which file format is image data compiled into a binary file? TIFF SVG CGM BMP
    11·1 answer
  • Pinterest, a visual bookmarking Website, logs more than 14 terabytes of new data each day, which means its storage needs are con
    10·1 answer
  • A flat panel detector’s detector element size determines what?
    10·1 answer
  • A constructor: A. always accepts two arguments B. has return type of void C. has the same name as the class D. always has an acc
    9·1 answer
  • 1. The Law of Superposition – the age of an object may be determined by the depth at which it is found, the deeper the object is
    14·1 answer
  • PLEASE I NEED HELP PLEASE PLEASE<br> Which function prompts the user to enter information?
    9·1 answer
  • Tape is magnetic tape which sound ca be recorded , true or false?
    9·1 answer
  • Is there a way to delete a question on brainly?
    8·2 answers
  • The. Model has the disadvantage of high project cost due to creation several prototypes
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!