Question: 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
Get step-by-step solutions from verified subject matter experts
