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)
- use static huffman algorithm to derive the codewords for the string ABCABCBBCBABDDEFBarrow_forward4. Palindrome String Given a string, find the minimum number of deletions required to convert it into a palindrome. For example, consider string ACBCDBAA. The minimum number of deletions required is 3. ACBCDBA A or ACBCDBAA ABCB Aarrow_forwardالفصل: الثاني الموضوع : واجب منزلي Assignment Question: (i): Given three numbers (numl, num2, and num3), write an algorithm to find and print the sumarrow_forward
- 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_forwardgiven a variable t that is assigned a tuple whose elements are strings, write some statements that use a while loop to count the number of tuple elements that are 4 character strings and assign that number to the variable four_letter_word_count. using pythonarrow_forward
- Let Σ= {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_forwardPART 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_forwardMatlabarrow_forward
- C Programming Language Note: Input and Output Must be the same Write in C Languagearrow_forwardInput: 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_forwardCode in python : function that gives length of string.arrow_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