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

  You will write a program that reads a text file

You will write a program that reads a text file, counts the number of words in the file, and the number of occurrences of each character. It will print to a file the number of words, and the number of occurrences of each character, as well as the ..

  Build a traffic light system - microcontroller system

Build the whole system with 3 RAG units and three puffin crossing units and build a team to work on this mini-project, be careful in selecting your team member.

  What are the contents of the array

What are the contents of the array after the subsequent loops complete - loops and also provide the iteration how to get it.

  A text file students.txt contains student records

A text file students.txt contains student records (name, date of birth, and GPA). Write a program that reads student records from students.txt and creates an array of student structures

  Write program which prompts user to enter numbers

Write down the program which prompts the user to enter numbers, findsout how many positive and negative values have been entered, and calculates sum and average of numbers entered.

  Your program should include two functions

Your program should include two functions. Function celsius_at_depth should compute and return the Celsius temperature at a depth given in kilometers. Function fahrenheit should convert a Celsius temperature to Fahrenheit.

  Program that will calculate the heat transfer of a substance

write a program that will calculate the heat transfer of a substance (water) given three different shapes. The user has to be able to input the type of shape, so that the computer can calculate area, and plug it back in to the equation for heat trans..

  Stability in an ever-changing technology world

Where do you think C++ and coding games in C++ is headed in the next five years? How about in the next 10 years? Do you think there are any significant improvements that need to be made to the code to ensure its stability in an ever-changing t..

  Program for keeping course list for each student in college

Write a program for keeping a course list for each student in a college. The information about each student should be kept in an object that contains the student's name and a list of courses completed by the student.

  Write a loan calculator program

Write a loan calculator program in C++ that displays monthly balances for user-specified loan terms. To be flexible, you decide to specify the loan terms in a file and provide that filename  entered from the keyboard. To keep things simple

  Prepare a program to get a number from the user

How will you prepare a program to get a number from the user and then demonstrate the output as the result above?

  Write a function named shift_right

The function should make sure that left is less than or equal to right, and that distance is greater than zero. If either of these conditions fails, the function should return the value 1 to indicate an error.

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