web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
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?

I have the same question (0)
  • Suggested answer
    Nya Profile Picture
    29,064 on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 156

#2
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans