Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is an anagram generator in the notes for Lecture 2. Write a dierent anagram generator that makes only one recursive call instead of n
This is an anagram generator in the notes for Lecture 2. Write a dierent anagram generator that makes only one recursive call instead of n recursive calls as is done by the program in the notes. Set up an experiment to compare the running times of the two programs. Produce a table showing your results. Carry out the calculations until you see a dierence in the results or until you have exhausted the resources necessary to run the anagram generator. Describe your results, and project the future behavior of these two algorithms.
def anagram(st): if st-": return ['] lout = [ ] for i in range(len(st): ['act', 'atc, 'cat', 'cta', 'tac, 'tca] 6 st2 = st[:i]+st[i+1 :] lout2 = anagram(st2) for w in lout2: lout.append(st[i]+w) return lout ana = anagram('cat') ana.sort) print ana, len(ana)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started