Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
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
Algorithm design with sorting. Each of n users spends some time on a social media site. For each i = 1, . . . , n, user i enters the site at time ai and leaves at time bi ≥ ai. You are interested in the question: how many distinct pairs of users are ever on the site at the same time? (Here, the pair (i, j) is the same as the pair (j, i)).Example: Suppose there are 5 users with the following entering and leaving times: Then, the number of distinct pairs of users who are on the site at the same time is five: these pairs are (1, 2), (1, 3), (2, 3), (4, 6), (5, 6). (Drawing the intervals on a number line may make this easier to see).(a) Given input (a1 , b1),(a2 , b2), . . . ,(an, bn) as above in no particular order (i.e., not sorted in any way), describe a straightforward algorithm that takes Θ(n2)-time to compute the number of pairs of users who are ever on the site at the same time, and explain why it takes Θ(n2)-time. [We are expecting pseudocode and a brief justification for its…
Write the sets A and B if A - B = {1, 5, 7, 8}, B – A ={2, 10}, and A N B = {{3, 6, 9
Find the cardinal num ber for the following sets. A = {100, 101, 102, 103,..., 159} B = {100, 102, 104, ..., 150} n(A)=
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