Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
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.)
The Knapsack Problem is a famous computer science problem that is defined as follows: imagine you are carrying a knapsack with capacity to hold a total of weight C. You are selecting among n items with values A={a_1, a_2, ... , a_n} and associated weights W={w_1, w_2, ... , w_n}. Here the weights and values are all positive (but not necessarily unique). You wish to maximize the total value of the items you select not exceeding the given weight capacity, i.e. maximize sum_{a in A} such that sum_{w in W} <= C. Please note that you can only select your items once.   a) We can reformulate this as a 2D bottom-up dynamic programming problem as follows. Define T_{i,j} as the highest possible value sum considering items 1 through i and total weight capacity j (j <= C). What is the base case i.e. T_{0,j} for all j and T_{i,0} for all i?, and  What is the loop statement?
Recursive filtering techniques are often used to reduce the computational complexity of a repeated operation such as filtering. If an image filter is applied to each location in an image, a (horizontally) recursive formulation of the filtering operation expresses the result at location (x +1, y) in terms of the previously computed result at location (x, y). A box convolution filter, B, which has coefficients equal to one inside a rectangular win- dow, and zero elsewhere is given by: w-1h-1 B(r, y,w, h) = ΣΣΤ+ i,y + ) i=0 j=0 where I(r, y) is the pixel intensity of image I at (x, y). We can speed up the computation of arbitrary sized box filters using recursion as described above. In this problem, you will derive the procedure to do this. (a) The function J at location (x,y) is defined to be the sum of the pixel values above and to the left of (x,y), inclusive: J(r, y) = - ΣΣ14.0 i=0 j=0 Formulate a recursion to compute J(r, y). Assume that I(r, y) = 0 if r <0 or y < 0. Hint: It may be…
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