Skip to content

Tushar joshi perfect string#11

Open
tusharjoshi4531 wants to merge 7 commits intomainfrom
TusharJoshi-PerfectString
Open

Tushar joshi perfect string#11
tusharjoshi4531 wants to merge 7 commits intomainfrom
TusharJoshi-PerfectString

Conversation

@tusharjoshi4531
Copy link
Contributor

My solution to Perfect string.

f(i) = number of perfect string of length 2 * i
g(i) = number of perfect strings of length 2 * i which cannot be partitioned into contiguous perfect strings.
c = number pf charecters

F(x) = sum(f(i), x^i) for i = 0 - inf
G(x) = sum(g(i), x^i) for i = 0 - inf

derived equations -
F(x) = F(x)G(x) + 1;
G(x) = cxF(x) - G(x)F(x) / c

after solving
F(x) = [1 / (1 - xc^2) ]- c * [(1 - sqrt(1 - 4(c - 1)x) / 2 (c - 1) (x)] * [(c - 1)x / (1 - xc^2)]

after maclaurin expansion
f(n) = c ^ 2n - c*(c - 1) sum(Catalan(i) * (c - 1) ^ i * (c) ^ (2 * (n - 1- i)), i = 0 - n - 1)

solution implemented in O(n) time and O(n) space

Time of execution = 2.9 s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants