Problems on all permutations

Assignment Help Mathematics
Reference no: EM13767153

Some problem require finding all permutations (different orderings)of a set of items. For a set of n items there are n! permutations. For example, given the set {1, 2, 3} there are six permutations:

{1, 2, 3} {2, 3, 1} {2, 1, 3} {3, 1, 2}{1, 3, 2} {3, 2, 1}

Write a recursively function that generates all the permutations of a set of numbers. Use the STL set class for all set operations and the STL linked list class to store and manipulate each individual permutation. When creating a set containing lists, make. The general  outline of a solution is given as followings:

The program will require storing a set of permutations of numbers that  you can implement in many ways, (e.g., linked list, linked lists of vector, array, etc.)Your program should call the recursive function with sets of several different sizes, printing the resulting set of permutation for each.

One solution is to first leave out the nth item in the set. Recursively find all permutations using the set of (n-1) items. If we
insert the nth item into each position for all of these permutations,  then we get a new set of permutations that includes the nth item. The base case is when there is only one item in the set, in which case the  solution is simply the permutation with the single item.

For example, consider finding all permutations of {1, 2, 3}. We leave  the 3 out and recursively find all permutations of the set {1, 2}.
This consists of 2 permutations:

{1, 2} {2, 1}

Now we insert the 3 into every position for these permutations. For  the first permutation we insert the 3 in the front, between 1 and 2,
and after 2. For the second permutation we insert the 3 in the front, between 1 and 2, and after 1.

{3, 1, 2} {1, 3, 2} {1, 2, 3} {3, 2, 1}{2, 3, 1} {2, 1, 3}

When creating a set containing lists, make sure to place a space between the last two >'s or the compiler may get confused. For
example, set <list<int>> defines a set where elements are linked lists containing elements of type int. the code set <list<int>>

without a space will likely produce a compiler error.
Use the following function declaration.

// Uses the permutations function to print all permutations of

// the first n whole numbers

voidprint_permutations(int n);
// Recursive function that returns a list contains all of the
// permutations of the given set of numbers

set<list <int>>permutations(const set<int>& numbers);

// Helper function for printing the contents of a list

voidprint_list(const list<int>& v);

Sample Output

717: {6,5,4,2,1,3}
718: {6,5,4,2,3,1}
719: {6,5,4,3,1,2}

720: {6,5,4,3,2,1}

Permuations of {1,2,3,4,5} :
1: {1,2,3,4,5}
2: {1,2,3,5,4}
119: {5,4,3,1,2}
120: {5,4,3,2,1}

Permuations of {1,2,3,4} :
1: {1,2,3,4}
2: {1,2,4,3}
23: {4,3,1,2}
24: {4,3,2,1}

Permuations of {1,2,3} :
1: {1,2,3}
2: {1,3,2}
3: {2,1,3}
4: {2,3,1}
5: {3,1,2}

6: {3,2,1}

Permuations of {1,2} :
1: {1,2}
2: {2,1}

Permuations of {1}:
1: {1}

Permuations of {}:

Press any key to continue . . .

Reference no: EM13767153

Questions Cloud

Issue related to test the hypothesis : Discuss the wisdom behind the strategy you would use to test the hypothesis from Question 3, and describe the additional steps you might take, depending on the results of your test.
Disadvantages to processing an outdoor crime scene : How you would document the scene? What evidence you would collect? The advantages and disadvantages to processing an outdoor crime scene
Purpose of the chart of accounts : What is the purpose of the chart of accounts? Why are internal controls and audit trails important in a computerized accounting system?
Define a piece of dna sequence : Please consider the features of Java classes, and then define a Java class for a DNA sequence object to include instance variable names and methods that you can use to define a piece of DNA sequence
Problems on all permutations : Write a recursively function that generates all the permutations of a set of numbers. Use the STL set class for all set operations and the STL linked list class to store and manipulate each individual permutation. When creating a set containing li..
Memo about time tickets and expense tickets : Prepare a 250- to 300-word memo about time tickets and expense tickets. Include an explanation about what each is used for, how the two are different, and what information may be found on each.
Communicating with peers and inmates : Communicating with peers and inmates in a correctional facility and Communicating with peers and inmates in a juvenile correctional facility
Accounting professional uses source documents : When completing the accounting cycle, the accounting professional uses source documents. Discuss the importance of the accuracy of these source documents. What problems might arise if the source documents are inaccurate?
Explain why acme fireworks should not operate as a sole : Explain why Acme Fireworks should not operate as a sole proprietorship. Recommend a new business entity, and provide rationale to support your recommendation

Reviews

Write a Review

Mathematics Questions & Answers

  Use k-map to find a minimal expansion as boolean products

Use K-map to find a minimal expansion as Boolean products of each of these functions. Also draw the logic circuit for problem a) and b).

  What is the marginal cost

what is the average cost per unite to produce 100 units?

  State truck drivers waiting in the queue

Truck drivers working for G.White and Sons earn $10 per hour on the average. Fruit loaders receive about $6 per hour. Truck drivers waiting in the queue or at the loading gate are drawing a salary but are productively idle

  Based on sample information find out 90 confidence interval

imagine that car middle east a car magazine is comparing that repair costs incurred during the first four years on two

  Is this a parameter or a statistic

The average grade on a midterm exam in a certain math class was an 88. Is this a parameter or a statistic?

  Estimate the maximum error in the calculated surface area

The circumference of a sphere was measured to be 84000 cm with a possible error of 050000 cm. Use linear approximation to estimate the maximum error in the calculated surface area.

  Evaluate the type of conic from the given equationindicate

evaluate the type of conic from the given equation.indicate which type of conic each of the following represents.1.

  Build an equation for a hyperboloid of two sheets

A function y = f(x) whose graph in the xy-plane, when rotated around the x-axis

  Estimate the length of the front wall

Estimate the length of the front wall, the area of the ceiling and the volume of the room.

  Exponentials-graphs and usefulness

Give an example of an exponential function. Convert this exponential function to a logarithmic function. Plot the graph of both the functions and post to the discussion forum. Discuss these functions and their graphs with your classmates.

  Assume jim had executed 15 splits before his last split of

assume jim had executed 15 splits before his last split of 20 seconds. if his eventual time in the road race isnbsp405

  What does the graph look like for the two parabolas

What does the graph look like for the two parabolas y=x^2 and y= -x^2 + 2x - 5 in the same coordinate plane? Find equations of the two lines simultaneously tangent to both parabolas.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd