Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Number of balanced parenthetical sentences of length n and depth <=d

(0) ShareShare
ReportReport
Posted on by 5

Let C(n, d) count the number of balanced parenthetical strings of length exactly n and nested depth at most d. So for instance: 
()(()) has length 6 and depth 2

(())((()(()))) has length 14 and depth 4

Is there any easy recursive relation on counting C(n, d) that one can use for dynamic programming. The base cases are clear:

C(n, d) = 0 if n is odd.

C(n, d) = 0 if d = 0 and n > 0

C(n, d) = 1 if n =0 and d= 0 (the empty string)

But what about otherwise?

I think something of the form

sum_{i <= n, j <=i/2} C(i, j)C(n-i, d-j) will eventually cover all possible strings (basically we're mixing strings of length i with strings of length n -i) but I'm pretty sure we suffer from a lot of overcounting here.

Is there a good recurrence relation for this, and if so, what would the runtime be like if implemented via dynamic programming?

  • Suggested answer
    Nya Profile Picture
    Nya 29,058 on at
    RE: Dynamic programming to count the number of balanced parenthetical sentences of length n and depth <=d

    Hi,

    This is the forum for Dynamics 365 Apps (Business Applications | Microsoft Dynamics 365) only.

    It is recommended to post your issue to another more appropriate forum.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans