Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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)=
Chapter 14 Solutions
Problem Solving with C++ (9th Edition)
Ch. 14.1 - Prob. 1STECh. 14.1 - Prob. 2STECh. 14.1 - Prob. 3STECh. 14.1 - Prob. 4STECh. 14.1 - Prob. 5STECh. 14.1 - If your program produces an error message that...Ch. 14.1 - Write an iterative version of the function cheers...Ch. 14.1 - Write an iterative version of the function defined...Ch. 14.1 - Prob. 9STECh. 14.1 - Trace the recursive solution you made to Self-Test...
Ch. 14.1 - Trace the recursive solution you made to Self-Test...Ch. 14.2 - What is the output of the following program?...Ch. 14.2 - Prob. 13STECh. 14.2 - Redefine the function power so that it also works...Ch. 14.3 - Prob. 15STECh. 14.3 - Write an iterative version of the one-argument...Ch. 14 - Prob. 1PCh. 14 - Prob. 2PCh. 14 - Write a recursive version of the search function...Ch. 14 - Prob. 4PCh. 14 - Prob. 5PCh. 14 - The formula for computing the number of ways of...Ch. 14 - Write a recursive function that has an argument...Ch. 14 - Prob. 3PPCh. 14 - Prob. 4PPCh. 14 - Prob. 5PPCh. 14 - The game of Jump It consists of a board with n...Ch. 14 - Prob. 7PPCh. 14 - Prob. 8PP
Knowledge Booster
Similar questions
- 1. Write an algorithm to determine whether a given element x belongs to a set S := {s1, . . . , sn}.arrow_forwardthe drop down bar is the selection you have to choose from for each answerarrow_forwardCorrect answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science. each individual has a rating chart portrayed by a variety of integers an of length n. You are currently refreshing the foundation, so you've made a program to pack these diagrams. The program functions as follows. Given an integer boundary k, the program takes the base of each adjoining subarray of length k in a. All the more officially, for a cluster an of length n and an integer k, characterize the k-pressure exhibit of an as a cluster b of length n−k+1, to such an extent that bj=minj≤i≤j+k−1ai For instance, the 3-pressure cluster of [1,3,4,5,2] is [min{1,3,4},min{3,4,5},min{4,5,2}]=[1,3,2]. A stage of length m is an exhibit comprising of m unmistakable integers from 1 to m in subjective request. For instance, [2,3,1,5,4] is a stage, however [1,2,2] isn't a change (2 shows up twice in the exhibit) and [1,3,4] is likewise not a stage (m=3 but rather there is 4 in the…arrow_forward
- Correct answer will be upvoted else downvoted. Computer science. You are given an exhibit a comprising of n (n≥3) positive integers. It is realized that in this exhibit, every one of the numbers with the exception of one are something very similar (for instance, in the cluster [4,11,4,4] all numbers aside from one are equivalent to 4). Print the list of the component that doesn't rise to other people. The numbers in the cluster are numbered from one. Input The main line contains a solitary integer t (1≤t≤100). Then, at that point, t experiments follow. The main line of each experiment contains a solitary integer n (3≤n≤100) — the length of the exhibit a. The second line of each experiment contains n integers a1,a2,… ,an (1≤ai≤100). It is ensured that every one of the numbers aside from one in the an exhibit are something very similar. Output For each experiment, output a solitary integer — the list of the component that isn't equivalent to other people.arrow_forwardWrite an algorithm that uses an adjacency matrix, A[n][n], to determine if a digraph contains the back edge of one of its edges. (The back edge of an edge (i, j) is the edge (j, i).) 2.arrow_forwardConsider a divide-and-conquer algorithm that calculates the sum of all elements in a set of n numbers by dividing the set into two sets of n/2 numbers each, finding the sum of each of the two subsets recursively, and then adding the result. What is the recurrence relation for the number of operations required for this algorithm? Answer is f(n) = 2 f(n/2) + 1. Please show why this is the case.arrow_forward
- You are given a list of randomly arranged numbers, for example (11,7,18,5,17,13). The triple (11,7, 5) is called the "inversion triple" because (5<7<11) in terms of value, while the index of 5 in the list is greater than the index of 7, and the index of 7 is greater than 11. Therefore, we can find 2 inversions in such list as follows: (11,7,5), and (18,17,13). Your main task is to find the total number of inversions in any given list. a) Design a brute-force algorithm to return the number of possible inversions, and analyse the complexity of your solution b) Develop a python code to implement your brute-force algorithm. [The marks depend on the correctness of the code, indentation, comments, test-case] c) Design a more efficient algorithm to do the same task with less complexity, and analyse the complexity of your solution. [Important instruction to be followed: Create an arbitrary unsorted list of 8 characters and use it to provide full explanation of how your proposed…arrow_forwardDesign a MapReduce algorithm that computes the sum of amultiset. The input is represented by pairs (x,m) where x is anelement of the multiset and m is its multiplicity, i.e., the number oftimes it is included in the set.For example, the multiset [3, 1, 2, 2, 3, 3, 2, 1, 3] is represented bythe pairs [(1,2),(2,3),(3,4)], and the desired output is 20.What is the map function? What is the reduce function? Describeany considerations you would take into account.arrow_forwardThere is a legend about a magical park with N × N trees. The trees are positioned in a square grid with Nrows (numbered from 1 to N from north to south) and N columns (numbered from 1 to N from west to east).The height (in metres) of each tree is an integer between 1 and N × N, inclusive. Magically, the height ofall trees is unique.Bunga is standing on the northmost point of the park and wants to count the number of visible trees for eachcolumn. Similarly, Lestari is standing on the westmost point of the park and wants to count the number ofvisible trees for each row. A tree X is visible if all other trees in front of the tree X are shorter than the treeX.For example, let N = 3 and the height (in metres) of the trees are as follows.6 1 87 5 32 9 4• On the first column, Bunga can see two trees, as the tree on the third row is obstructed by the othertrees.• On the second column, Bunga can see all three trees.• On the third column, Bunga can see only the tree on the first row, as the…arrow_forward
- solve it by the OUBILD PLEASEarrow_forwardWrite a function find_equivalent_matchings that takes a matching and returns all matchings with the same pattern (including the original one). Using this function, draw all matchings equivalent to {(0, 7), (1, 4), (2, 3), (5, 6)}. You might find it helpful to generate all permutations of a list using itertools.permutation (imported above) as in the following code template. perms=permutations (list_of_items) for p in perms:arrow_forwardJava Code Only Sahil is an outstanding entertainer. He is expert in what he does. At a day, he accepted Samir's challenge to plant 20 million trees by 2020. Currently, there are N trees (numbers 1 to N) planted in different places in the row; for each valid I, the location of the i-Ayi tree. A bunch of trees is good if for each tree in this set (let's say its place in x), there is a tree in x - 1 and / or a tree in x + 1. Sahil task is to plant more trees (perhaps zero) in such a way that the effect of all the trees planted (the first N trees and the ones planted by Sahil) is good. It is only allowed to plant trees in complete (perhaps unfavorable) areas. Help Sahil to find the minimum number of trees they need to plant to achieve that using Java Programming. Input: 1 417 Output: 2arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education