Explanation of Solution
The algorithm for lists all possible rearrangements of the symbols in a string of five distinct character is shown below:
Step 1: Start
Step 2: Define the function “permutationFucntion” that is for returns the all possible list of rearrangements for given string using “join” function.
Step 3: Define the function “permuteFunction” that is for compute the rearrangement for given string with three arguments such as “string”, “starting index” and “last index”.
If starting index is equal to last index
Display the string by calling the function “permutationFunction”.
Else
Check the range of starting index and last index using “for” loop.
Swap the string index using “nstr[startIndex], nstr[i] = nstr[i], nstr[startIndex]”.
Recursively call the function “permuteFunction” with given string, increment of starting index and last index.
After calling function, then swap the string index using “nstr[startIndex], nstr[i] = nstr[i], nstr[startIndex]”.
Step 4: Assign the sample string
Step 5: Compute the length of string
Step 6: List the given sample string
Step 7: Call the permutation function with list string, value of starting index and “length of string – 1”.
Step 8: Stop
Algorithm Explanation:
The given algorithm is used to lists all possible rearrangements of given string of five distinct characters.
- From the given algorithm, the function “permutationFunction” is used to displays the list of rearrangement string using “join” function.
- Then compute the possible rearrangement using the function “permuteFunction”.
- In this function, first check whether the staring index is equal to the last index...
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Computer Science: An Overview (12th Edition)
- 1. Design an algorithm to find the weighted sum of four test scores (https://en.wikipedia.org/wiki/Weight_function). Assume that the weights have been accurately calculated in advance such that their sum equals one. Your algorithm must-read in the four test scores and four corresponding weights in the following order: score1 weight1 score2 weight2 score3 weight3 score4 weight4 Write your algorithm such that it can be run with any set of data values. However, you can test your algorithm on the following sample data to verify that the result is 70: 90 0.10 80 0.20 70 0.30 60 0.40 2. Write an algorithm that prompts the user for the radius, in inches, and price of a pizza, and then reads in those values. Finally, have the algorithm compute and output the pizza’s cost per square inch. 3. Sports exercise advisor algorithm. In this algorithm you will start out with a temperature value in Celsius, so you do not need to ask the user for it. First, convert the temperature to Fahrenheit.…arrow_forward(Computation) A magic square is a square of numbers with N rows and N columns, in which each integer value from 1 to (N * N) appears exactly once, and the sum of each column, each row, and each diagonal is the same value. For example, Figure 7.21 shows a magic square in which N=3, and the sum of the rows, columns, and diagonals is 15. Write a program that constructs and displays a magic square for a given odd number N. This is the algorithm:arrow_forwardLet Σ= {Ac,BA,bcb,cd,ab,f,d,e}. (a) Identify valid strings and Find the length of the valid given below strings • fefBAfbcbcdAcfab • BAeffBAAcbcbab • bcbefabfABAAceddbcb Note: factorize each string for finding their lengtharrow_forward
- PART 2 Answered only if you Have answered part 1.......plase skip it if you dont know the correct answer i need it urgent. Will doewnvote in case of wrong or copied answers from chegg or bartleby! A regular expression (shortened as regex or regexp; also referred to as rational expression) is a sequence of characters that specifies a search pattern. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation. using regex create a python program to verify the string having each word start from 'j'? It should return True otherwise false.arrow_forwardProgramming Language :- Carrow_forwardMatlabarrow_forward
- Input: a string in a line. ➢ Output: Print the pattern and the repeated count if there is a repeated pattern, Print "none" otherwise. ➢ Task: Design an algorithm in pseudocode/code to for the problem and write down the Algorithm analysis. The complexity of the algorithm must be in O(n). ➢ PS: You use the algorithm for string matching taught in class. The repeated pattern is valid only from the first character.arrow_forwardPython program to find palindrome words in any sentence.arrow_forwardDesign an algorithm to find the weighted average of four test scores. The four test scores and their respective weights are given in the following format: (9) test Scorel weight Test Scorel For example, sample data is as follows: 75 0.20 95 0.35 85 0.15 65 0.30arrow_forward
- plese code in python The midfix of 3 is the middle 3 characters of a string. Given a string input, output the middle three characters of that string. Assume the word length is always odd and at least three characters. Ex: If the input is: xxxtoyxxx the output is: Midfix: toyarrow_forwardWrite a program that searches for the given string in the given sentence and if the word is found then prints the starting index of the places of this word to the screen Use C languagearrow_forwardpython wap to generate a random string of length 20 and conatins uppercase lowercase digits puncutation in itarrow_forward
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr