Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a recurrence relation T(n) such that T(n) is the number of possible permutations of a word of length n such that all n characters

Write a recurrence relation T(n) such that T(n) is the number of possible permutations of a word of length n such that all n characters are distinct. Solve the obtained recurrence relation to get a closed formula for the number of possible permutations for each word.

C++ Code: Displays all possible permutations of a word

// this function prints all the permutations of a user entered string void permutation(string word, string sstore) { // test if word was entered if (word.size() != 0) { // rotates all characters to the beginning one at a time for (int i = 0; i < word.size(); i++) { // take the first character and store it permutation(word.substr(1), sstore + word[0]); // rotate and move the second character to the beginning rotate(word.begin(), word.begin() + 1, word.end()); } } // if no word was entered else { cout << sstore << endl; return; } } // picks up user input and sends to the function int main() { string word; cout << "Enter a word: "; cin >> word; cout << endl; permutation(word, ""); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions