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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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