Solve the following problem in your favorite programming language and send the program to us.
Problem: [L-Systems]: L-systems are used to model naturally occurring patterns in nature such as growth of trees, growth of multicellular organisms, fractals etc. by recursively applying a set of simple grammar rules over a set of variables starting with an Axiom.
For example: Growth of Algae in L-systems would be modelled as.
variables : A B
constants : none
axiom : A {starting character string}
rules : (A → AB), (B → A)
which produces:
n = 0 : S=A
n = 1 : S=AB
n = 2 : S=ABA
n = 3 : S=ABAAB
n = 4 : S=ABAABABA
n = 5 : S=ABAABABAABAAB
Given the upper bound ‘n’, design a class D for L-systems with variables, constants, axiom and rules. Write a function ‘produce’ that takes in the object of ‘D’ and ‘n’ as parameters and returns the L-systems string ‘S’. Tell the space and time complexity. How can you optimize your solution and what's the optimized space and time complexity?