def ab_equal (n, k, current): Print out all of the strings of a's and b's of length n so that the number of a's and b's are equal. For n = 2, there's ab and ba. For n = 3 there are no strings since...





def

ab_equal
(n, k, current):



Print out all of the strings of a's and b's of length n so that the number of a's and b's are equal.



For n = 2, there's ab and ba.  For n = 3 there are no strings since they'd have to have 2 a's and 1 b, or 2 b's a 1 a so not equal.  For n = 4, there will be 6 of these strings, and for n = 5, zero again.




Hint:
use k to track the difference between a's and b's.  So for instance if your current is aaabb then k should be equal to either 1 or -1 (your choice depending).



When you call the function, you should call it from your main or testing function with the length in the n parameter, 0 should be put into the k parameter, and then an empty string will be passed in for current.




What length do you want to run?

4



aabb



abab



abba



baab



baba



bbaa



Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here