Problem related to permutation

Assignment Help C/C++ Programming
Reference no: EM13725642

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}

Question: 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);

Reference no: EM13725642

Questions Cloud

Describe the hypothetical organization : Describe the hypothetical organization your team will use for your final marketing plan presentation, including geographic location and mission
How did the united states respond to your experience : Where did you go? Describe your experience at the camp. What happened to your family? How did the United States respond to your experience?
Creating an overall organizational security plan : Write a 1,750- to 2,450-word paper (not counting your references page) that summarizes and integrates the following major concepts of physical security when creating an overall organizational security plan
Create presentation on health care marketing plan : Create an outline based on your Health Care Marketing Plan Presentation due in Week Six. The purpose of this outline is to ensure you are on the right track with your final project
Problem related to permutation : 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..
Determine implications for each of computed elasticities : Compute the elasticities for each independent variable. Note: Write down all of your calculations - Determine the implications for each of the computed elasticities.
Write a lifestyle profile for the neighborhood : Write a lifestyle profile for the neighborhood that can be used as the demographic profile for potential patients at your facility
Strategies for minimizing resistance to change : Outline six strategies for minimizing resistance to change, and debate ways to effectively create a sense of urgency for change (McShane & Von Glinow, 2013).
Write an essay on the fugitive slave act : I need original Annotated Bibliography for 4 sources: Primary Sources 1. The Fugitive Slave Act and 2. Levi Coffin's Underground Railroad Station.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program to implement a simple batch operating system

Write a program C/C++ to implement a simple batch operating system. Develop a simple loader, scheduler, memory manager, and shell.

  Write a program that will read in 4 test scores per line

Write a program that will read in 4 test scores per line. Print the total number of points earned, your program should work for any number of lines of data.

  calculates the average rainfall

Write a program that calculates the average rainfall for three months. The program should ask the user to enter the name of each month, such as June or July, and the amount of rain (in millimeters) that fell each month.

  Create a friend class

Create a Friend class that contains a first name, last name, a birthday, and a telephone number. Create a Contacts class that contains an array of Friend as well as the owner's name and cell phone Number.

  Complete the 8 queens 2 dimensional array

Complete the 8 queens 2 dimensional array program with backtracking. please change the below program using backtracking  and please run before posting it . the program suppose to print 92 solution . amd also comment before each line to better unde..

  Write a c++ program which will calculate the monthly balance

Write a C++ program which will calculate the monthly balance of a debt. Each month a payment is made on the balance, and interest is added to the balance using a fixed percentage rate.

  What is the output of this code fragment as it is written

In the code fragment below, the programmer has almost certainly made an error in the first line of the conditional statement.

  What is the output of the program below

What is the output when the following code fragment is executed?

  Set of nested for loops

Use a set of nested for loops to display the letters "R" and "B" in patterns as they might appear on a checkerboard.

  Write a program at level that will accept a lower case

Write a program at level 3 (Instruction Set Architecture Level) that will accept a lower case letter and output the uppercase version of the letter.

  Your city''s parking violation

Your city's Parking Violation Bureau wants you to write a program to compute fines for parking violations.

  Create the appropriate constructor, getters and setters

Create the appropriate constructor, getters and setters for the class. Create an instance of Student for each of the students listed above from array. Construct the instance with lastname, firstname, and job.

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