Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862218
Author: Walter Savitch
Publisher: PEARSON
Question
Book Icon
Chapter 14, Problem 8PP
Program Plan Intro

Finding all permutations for a set

Program Plan:

  • Include required file.
  • Define the structure for node.
    • Declare elements in “vector” type.
    • Declare variable for next value in “NodeValue” type.
  • Declare function for display permutations.
  • Declare function for compute permutations with recursively.
  • Declare function for display vector elements of set.
  • Define main function.
    • Call the function “displayPermutations” with one parameter.
  • Define function “displayPermutations”.
    • Create a pointer for node.
    • Declare the set in “vector” type.
    • Fill the set with first “n” whole elements.
    • Call the function “displayVectorElements” to print the vectors.
    • Then compute the permutation for given set by calling the function “recursivePermutations”.
    • Performs “while” loop. This loop executes until the pointer is equal to “NULL”.
      • Display the values in set by calling the function “displayVectorElements”.
      • Then delete and move to the next value.
  • Define function “recursivePermutations”.
    • This function is used to returns a list holding all of the permutations of the given list of elements.
    • In this function, first assign the pointer list to “NULL”.
    • Then performs base case if the size of the vector element is “1”. Otherwise performs recursive case.
    • Compute the permutations for smaller set of elements by recursively call the function “recursivePermutations”.
  • Define function “displayVectorElements”.
    • This function is used to display the elements of set.

Blurred answer
Students have asked these similar questions
In chess, a walk for a particular piece is a sequence of legal moves for that piece, starting from a square of your choice, that visits every square of the board. A tour is a walk that visits every square only once. (See Figure 5.13.) 5.13 Prove by induction that there exists a knight’s walk of an n-by-n chessboard for any n ≥ 4. (It turns out that knight’s tours exist for all even n ≥ 6, but you don’t need to prove this fact.)
For each, draw the recursion tree, find the height of the tree, the running time of each layer, and the sum of running times. Then use this info to find the explicit answer for T(n).   a. T(n) = 2T(n/4) + √ n (n is a power of 4 (n = 4^k) for some positive integer k)   b. T(n) = 9T(n/3) + n^2 (n is a power of 3 (n = 3^k) for some positive integer k)   c. T(n) = T(n/2) + 1 (n is a power of 2 (n = 2^k) for some positive integer k)
In computer science and mathematics, the Josephus Problem (or Josephus permutation) is a theoretical problem. Following is the problem statement: There are n people standing in a circle waiting to be executed. The counting out begins at some point (rear) in the circle and proceeds around the circle in a fixed direction. In each step, a certain number (k) of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. Given the total number of persons n and a number k which indicates that k-1 persons are skipped and kth person is killed in circle. The task is to choose the place in the initial circle so that you are the last one remaining and so survive. For example, if n = 5 and k = 2, then the safe position is 3. Firstly, the person at position 2 is killed, then person at position 4 is killed, then person at position 1…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education